This is a basic fix im just seeing who can figure it out.
local Key = script.Parent
local Player = game.Players.LocalPlayer
Key.ClickDetector.MouseClick:Connect(function()
Player.leaderstats.Wins.Value = Player.leaderstats.Wins.Value + 1
end)
error is “Workspace.Key.Handle.Script:5: attempt to index nil with ‘leaderstats’”
try Player:WaitForChild("leaderstats") instead of Player.leaderstats
If that gives a warning like “infinite wait possible” or something then leaderstats probably isn’t a child of the Player
local Key = script.Parent
local Player = game.Players.LocalPlayer
Key.ClickDetector.MouseClick:Connect(function()
local WinStat = Player:WaitForChild("leaderstats"):WaitForChild("Wins")
WinStat.Value += 1
end)
Please don’t do this. If you update it in a LocalScript, it will not replicate to the server. However, since you’re using a ClickDetector, you can use the Player object that is passed along with it. For example:
local Key = script.Parent
Key.ClickDetector.MouseClick:Connect(function(Player)
Player.leaderstats.Wins.Value += 1 -- Simplified with += operator
end)
Yes, I’m very well aware, you still replied to the wrong user. Considering game.Players.LocalPlayer is fetched this was clearly intended to be a local script. Good chance the original poster doesn’t mind the stats only reflecting locally, for some games that’s fine.