Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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

0
Is this script in a local script? T1mes 230 — 5y
0
When you use .LocalPlayer the script has to be in a localscript mixgingengerina10 223 — 5y
0
You don't need to define Player cause you already defined it, remove the 2nd line and it will work greatneil80 2647 — 5y

2 answers

Log in to vote
0
Answered by
amanda 1059 Moderation Voter
5 years ago

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.

0
Thank you, it worked kezimofficalstudio -3 — 5y
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? amanda 1059 — 5y
0
how? kezimofficalstudio -3 — 5y
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" amanda 1059 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Thank you, it worked

Answer this question