Help with wins leaderstats script

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)

That’s the exact same as what I just said

Maybe you put this in a ‘script’ vs a ‘localscript’ ?

You didn’t mention waiting for the IntValue instance named “Wins”, also I was just fixing up the formatting.

This wouldn’t work in a server script because game.Players.LocalPlayer is only accessible from local scripts.

index nil with waitforchild thats the error

Then its probably in a server script

index nil with wait for child thats the error

Copy the code into a local script & place it inside the StarterPlayerScripts folder.

Yeah, thats why I suggested it as a reason why its throwing an error.

correct this was just to see who is good at scripting I had it in a Script" soo it errors because I don’t have it in a local script “good job”!

Okay, well I gave that solution 6 posts before that, ha.

Well yeah your right.
ill give it to you.

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)

You replied to the wrong user.

I don’t think he is planning to use it, he was trying to make a quiz for us.

No, I replied to you. You said:

Which wouldn’t replicate, since it’s a LocalScript.

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.