I made a clicking tool, when you click, it adds 1 to your leaderstats. simple right? but then I get an error when ever I click it…
My Leaderstats script:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local clicks = Instance.new("IntValue",leaderstats)
clicks.Name = "Clicks"
end)
my tool script:
local player = game.Players.LocalPlayer
script.Parent.Activated:Connect(function()
player.leaderstats.Clicks.Value +=1
end)
my error:
Players.Kimathi4theWin.Backpack.Tool.AddToClicks:4: attempt to index nil with 'leaderstats' - Server - AddToClicks:4
Try this script:
local player = game.Players.LocalPlayer
local Value = player:WaitForChild("leaderstats").Clicks.Value
script.Parent.Activated:Connect(function()
Value = Value + 1
end)
1 Like
Players.Kimathi4theWin.Backpack.Tool.AddToClicks:2: attempt to index nil with 'WaitForChild' - Server - AddToClicks:2
Try it:
game.Players.PlayerAdded:Connect(function(p)
script.Parent.Activated:Connect(function()
p:WaitForChild("leaderstats").Clicks.Value += 1
end)
end)
If it doesn’t work send me error
1 Like
offizen
(offizen)
May 11, 2021, 7:54am
#5
You are using a Server Script, LocalPlayer is nil on the Server
1 Like
He don’t needs to use LocalPlayer
offizen
(offizen)
May 11, 2021, 7:55am
#7
I am telling him why it does not work
offizen
(offizen)
May 11, 2021, 7:55am
#8
You could either use RemoteEvents to Fire the Server to give you the points, or to make the Tool completely ServerSided and reference the Player another way
Remote Events are more complicated and again he don’t need to use LocalPlayer
1 Like
offizen
(offizen)
May 11, 2021, 7:58am
#10
RemoteEvents are not too difficult…
1 Like
Yes, but not for begginers what’s better for them?
offizen
(offizen)
May 11, 2021, 8:00am
#12
It’ll be good practice to get into using them
1 Like
i’m not a beginner lol dw i’m pretty experienced i just got mixed up lmao
don’t worry i use remote events and functions everyday