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

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
1
Answered by 6 years ago

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

0
game.Players.LocalPlayer also works in local scripts. SystemFormat 149 — 6y
0
Thanks! Works perfectly. meteorcrasher118 35 — 6y
0
Feel free to accept the answer. User#6546 35 — 6y
Ad

Answer this question