Hello, I’m new to LUA, although I have a lot of scripting experience.
I am creating a basic loading script and assigning variables to learn.
I’m being given this error.
Attempt to index nil value.
PlayerInfo = {
[0] = {
PlayerName = "default",
admin = 0,
Job = 0,
}
}
-- Event handler for when a player is connecting
AddEventHandler('playerJoining', function(oldIDs)
local src = source
if src == 1 then
PlayerInfo[src].admin = 1
end
local admin = PlayerInfo[src].admin
print('ADMIN LEVEL '..admin)
end)
In Lua, arrays (or tables) are 1-indexed by default, which means that the first element (PlayerInfo in this case) is accessed with index 1, not 0. In your code, you have defined the PlayerInfo table with the first element having an index of 0