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

how do i fix "attempt to index local 'player' (a nil value)"?

Asked by 5 years ago
Edited 5 years ago

ok so everytime i go in game to test, it constantly says attempt to index and all that, never works - it's for a shop GUI that gives you a gun when clicked

script.Parent.MouseButton1Click:Connect(function()

    local RS = game:GetService("ReplicatedStorage")

    local item = RS:WaitForChild("GlockDrum")

    local player = game.Players.LocalPlayer

    local cloned = item:Clone()

    cloned.Parent = player.Backpack

    end)
0
So today I had the exact same problem and the reason why this was happening was because LocalPlayer does not work in server scripts. I instead used a module script to give it to me. Mr_Unlucky 1085 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

If this is a script then localplayer will not work. How you could fix this is by passing a plr argument in the Mouse click event "script.Parent.MouseButton1Click:Connect(function(player)" and then removing the local player variable.

Hope this helps!

0
could you possibly copy what i put and add what you are talking about to it, i dont really understand PappyXCuasi 0 — 5y
Ad

Answer this question