Jump to content

[Help] attempt to index upvalue "users" (a nil value)


Layla

Recommended Posts

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 by Layla
Link to comment
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
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 by Layla
Link to comment

"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 by MrTasty
Link to comment
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
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 by Mqtyx
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...