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

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

Asked by 4 years ago
Edited 4 years ago

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)
0
are you using a local script XxOPGUYxX1234567 221 — 4y
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 XxOPGUYxX1234567 221 — 4y
0
I was gonna post a question asking how to do that, thank you! Shadic1270 136 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

0
I did Shadic1270 136 — 4y
0
It actually worked, tysm Shadic1270 136 — 4y
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. kkkeelan999 92 — 4y
Ad

Answer this question