A lot of beginner scripters try to use LocalPlayer in Server Scripts, I’ve seen it before.
A lot of beginner scripters try to use LocalPlayer in Local Scripts, I’ve seen it before.
The thread has been marked as solved, please stop mentioning me, thanks.
??? LocalPlayer is fine in Local Scripts. I was saying in Server Scripts it doesn’t work
Doesn’t change the fact that beginner scripters try to use LocalPlayer in Local Scripts (they just end up being successful).
This is going off-topic, in future direct any recommendations to the original poster.
well guess what "that was still not the case, ha.
your right just doesnt work. lol i thought this was easy.
So he decides he wants server-side stats.
local Key = script.Parent
Key.ClickDetector.MouseClick:Connect(function(Player)
local WinStat = Player:WaitForChild("leaderstats"):WaitForChild("Wins")
WinStat.Value += 1
end)
Server script, place it inside the part & place the part somewhere in the workspace.

Like the above. The stats will now reflect to the whole server & not just locally.
This is a generally easy fix. You should change a few things.
First, the error is most likely caused due to
local Player = game.Players.LocalPlayer
You are unable to use game.Players.LocalPlayer within a server script.
To fix this, you can define the player using the MouseClick function, like this:
Key.ClickDetector.MouseClick:Connect(function(player) -- put player in here to access the player
print(player.Name)
end)
And when you are finding something within the player, make sure you use WaitForChild as it may have not loaded yet! Like this:
Key.ClickDetector.MouseClick:Connect(function(player) -- put player in here to access the player
player:WatForChild("leaderstats").Wins.Value = player:WaitForChild("leaderstats").Wins.Value + 1 -- use WaitForChild() as it might have not loaded!
end)
Another thing that you can do (optional) to shorten the code, is to change
player:WatForChild("leaderstats").Wins.Value = player:WaitForChild("leaderstats").Wins.Value + 1
to
player:WatForChild("leaderstats").Wins.Value += 1