Why does my table values return nil when i clearly initialized them?
- by user3717078
players = {}
function newPlayer(name)
players[name]={x = 200, y = 100} --assign each player their x and y coordinates, which is x: 200 and y: 100
end
function checkPosition(name?) -- Do i need a parameter?
if players[name].x == 200 and players[name].y == 100 then --says players[name].x is a nil value
print("good")
else
print("bad")
end
end
Error: attempt to index ? (a nil value)
Current Situation: The code above says players[name].x is a nil value, I would like to know why since i thought i assigned it in the function newPlayer.