Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

attempt to index local 'player' (a nil value)???

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Down:connect(function()
	game.Players[player.Name].LeaderStats.EXP.Value = game.Players[player.Name].LeaderStats.EXP.Value + 1
end)

I get this error: attempt to index local 'player' (a nil value)

Help? thanks!

2 comments

0

Also to build off of what eLunate said, leaderstats have to be all lowercase to work.

0

no, it is a custom made leaderboard, so I made a model named "LeaderStats" in the player to hold values to update the custom leaderboard and used a DataStore to save those values

1 answer

Regular Scripts can't access LocalPlayer

My best guess here is that player is nil literally because you're using a regular Script and you're trying to access LocalPlayer. I'd recommend either using RemoteEvents and a LocalScript, or finding another way of working out who the player for the event is.

2 comments

0

In addition to this answer, why go through the whole process of going through game.Players if you have a direct access to the LocalPlayer via the variable?

0

I was going to mention it but I figured that this guy isn't really at that point of using his brain.

This discussion is preserved as it was. New answers, comments, and votes are closed.