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

Attempting to index local 'Player' (a nil value)?

I've been at this for a while, but I don't seem to get it. It doesn't add +1 to the SP value, am I doing something wrong?

local text = script.Parent.Parent.Parent.Frame2.TextLabel
local PointsService = game:GetService("PointsService")
local button = script.Parent

button.MouseButton1Click:connect(function(Player)
	text.Text = "+1 SP"
	script.Parent.Sound:Play()
	button.Position = UDim2.new(math.random(4), math.random(4), math.random(4))
	Player.leaderstats.SP.Value = Player.leaderstats.SP.Value + 1
end)

Everytime I click the button, the message,

"16:25:22.013 - Players.meteorcrasher118.PlayerGui.ScreenGui.Frame.TextButton.Script:9: attempt to index local 'Player' (a nil value)"

keeps appearing.

1 answer

✓ Accepted answer

GuiButton.MouseButton1Click does not have a Player argument. Go up from script until you hit the player, for a solution which works in both LocalScripts and regular Scripts

3 comments

0

game.Players.LocalPlayer also works in local scripts.

0

Thanks! Works perfectly.

0

Feel free to accept the answer.

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