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

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

I have such a problem in this script when I click does not give me these points in leaderstats is that there is such an error: attempt to index local 'player' (a nil value) line 3 and here is the script:

script.Parent.MouseClick:Connect(function(Player)
	Player = game.Players.LocalPlayer
	Player.leaderstats.Strength.Value = Player.leaderstats.Strength.Value + 1

please help

3 comments

0

Is this script in a local script?

0

When you use .LocalPlayer the script has to be in a localscript

0

You don't need to define Player cause you already defined it, remove the 2nd line and it will work

2 answers

✓ Accepted answer

Remove line 2. The player who clicks the part containing the ClickDetector is passed to the Player parameter, so you do not need to redefine it.

Also, just in case you didn't know, you also need to end your function and close out the Connect method.

Do this by writing end) on a new line following the completion of your function.

script.Parent.MouseClick:Connect(function(Player)
	Player.leaderstats.Strength.Value = Player.leaderstats.Strength.Value + 1
end)

If you have additional errors, let us know and edit your question to include your updated and complete script.

4 comments

0

Thank you, it worked

0

No problem, happy to hear your issue is resolved! Could you mark my answer as correct so that people know that it is resolved?

0

how?

0

I haven't posted a question so I am not 100%. Look for a button above or below my answer. It might say something like "accept answer"

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