Layla Posted September 3, 2018 Share Posted September 3, 2018 (edited) Hello can anyone tell me or help me to solve this error? Quote Debugscript 3 says error attempt to index upvalue "users" (a nil value) local users = { ["layla"] = 5, } addEventHandler("onServerPlayerLogin", root, function() local name = exports.serverCore:getPlayerAccountName(source) if users[name] ~= nil then setElementData(source,"premium", users[name], true) end end) Kindly please help with this Edited September 3, 2018 by Layla Link to comment
WorthlessCynomys Posted September 3, 2018 Share Posted September 3, 2018 You miss a space between the equation sign and the name of the variable. That should be the problem. Link to comment
Layla Posted September 3, 2018 Author Share Posted September 3, 2018 12 minutes ago, WorthlessCynomys said: You miss a space between the equation sign and the name of the variable. That should be the problem. Still the same. I still got the error. Link to comment
WorthlessCynomys Posted September 3, 2018 Share Posted September 3, 2018 local users = { ["layla"] = 5, } addEventHandler("onServerPlayerLogin", root, function() local name = exports.serverCore:getPlayerAccountName(source) if (users[name]) then setElementData(source,"premium", users[name], true) end end) This should work. It might be the same as yours now, but maybe you did something wrong. With this if you registered with the username layla, it should work. Link to comment
Layla Posted September 3, 2018 Author Share Posted September 3, 2018 (edited) 21 minutes ago, WorthlessCynomys said: local users = { ["layla"] = 5, } addEventHandler("onServerPlayerLogin", root, function() local name = exports.serverCore:getPlayerAccountName(source) if (users[name]) then setElementData(source,"premium", users[name], true) end end) This should work. It might be the same as yours now, but maybe you did something wrong. With this if you registered with the username layla, it should work. 2 I still got the same error on line 11 Edited September 3, 2018 by Layla Link to comment
WorthlessCynomys Posted September 3, 2018 Share Posted September 3, 2018 1 minute ago, Layla said: I still got the same error on line 13 Well. Okay... I'm not at a PC to test it and It is good with the syntax as I see, so I'm sorry, I can't help you now. Link to comment
Addlibs Posted September 3, 2018 Share Posted September 3, 2018 (edited) "error attempt to index upvalue "users" (a nil value)" This means that the local variable users is a nil value, and you tried to index it (users[name]). Is what you posted here the whole code? Perhaps somewhere in the full code users is changed to a nil? The snippet alone seems to be correct so I don't know why users would be a nil value. Edited September 3, 2018 by MrTasty Link to comment
Layla Posted September 3, 2018 Author Share Posted September 3, 2018 3 minutes ago, MrTasty said: "error attempt to index upvalue "users" (a nil value)" This means that the local variable users is a nil value, and you tried to index it (users[name]). Is what you posted here the whole code? Perhaps somewhere in the full code users is changed to a nil? The snippet alone seems to be correct so I don't know why users would be a nil value. We have the same thoughts Link to comment
DockDadDan Posted September 4, 2018 Share Posted September 4, 2018 (edited) addEventHandler("onServerPlayerLogin", root, function() local name = exports.serverCore:getPlayerAccountName(source) if (users[name]) then setElementData(source,"premium", users[name], true) end end) I assume you put this piece of code in another .lua file while you defined 'users' as a local variable which means it wouldn't be accessible in any other .lua file except the file it was defined in. If I guessed it right, you'd have to remove that 'local' beside users variable. Edited September 4, 2018 by Mqtyx Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now