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

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

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)

1 comment

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.

1 answer

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!

1 comment

0

could you possibly copy what i put and add what you are talking about to it, i dont really understand

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