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

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

So i have trying to do this script but i keep getting this error pls help me

script.Parent.MouseButton1Click:connect(function()
 local RS = game:GetService("ReplicatedStorage")
 local item =  RS:WaitForChild("Gravity Coil")
 local price = 50
 local player = game.Players.LocalPlayer
 local stats = player:WaitForChild("leaderstats")

if stats.Points.Value == price then 
  stats.Points.Value = stats.Points.Value - price
  local cloned = item:Clone()
  local cloned2 = item:Clone()
  cloned2.Parent = player.Backpack
  cloned.Parent = player.StarterGear
 end
end)

3 comments

0

are you using a local script

0

also instead of doing stats.Points.Value == price, I would do stats.Points.Value >= price so it can be equal to or greater than otherwise it always has to be equal to

0

I was gonna post a question asking how to do that, thank you!

1 answer

✓ Accepted answer

Well, first off, it would be nice if you could put it in a code block because it would be way easier to read. Also, If you have your code written out like that and it's not a copy+paste error, I suggest taking a bit of time fixing it up so it's easier to read.

Since it's hard to read and you didn't give much information, I can't help very well. But to me, it looks like you may be trying to access the local player from a server script. If it's in a server script you can't use game.Players.LocalPlayer to get the local player. If it's something to do with the player, always use local scripts.

3 comments

0

I did

0

It actually worked, tysm

0

Glad to help. Also, if you don't mind could you set this to the correct answer? Others would know it's been answered that way.

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