Adding to a leader stat

I was wondering how I could add a certain value to a local players leader stat. I have tried something here but it doesn’t seem to be working -

local guipart = game.Workspace.guipart
local Players = game:GetService("Players")

local function End(clonedgui)
	local Players = game:GetService("Players")
	local Player = Players.LocalPlayer
	local minutes = 0
	local seconds = 15
	repeat
		if seconds <= 0 then
			minutes = minutes - 1
			seconds = 59
		else
			seconds = seconds - 1
		end
		if seconds < 10 then
			clonedgui.TextLabel.Text = tostring(minutes)..":0"..tostring(seconds)
		else 
			clonedgui.TextLabel.Text = tostring(minutes)..":"..tostring(seconds)
		end
		wait(1)
	until minutes <= 0 and seconds <= 0
	if minutes <=0 and seconds <=0 then
		clonedgui:Destroy()
		Players.LocalPlayer.leaderstats.Stage.Value = Players.LocalPlayer.leaderstats.Stage.Value + 1
	end
		end

At the end of the script the local player is supposed to gain a value of one but studio just gives me the error “ServerScriptService.Main:25: attempt to index nil with ‘leaderstats’”. How would I fix this?

are you sure there is a folder named leaderstats inside the player?

1 Like

Yes, I made a leaderstat named stage.

No, he’s asking is there a folder that is parented to the player named leaderstats?

You could also try doing:

Players.LocalPlayer:WaitForChild("leaderstats").Stage.Value += 1

if there is a leaderstat and you know it but its not working.

Gives me an error “ServerScriptService.Main:25: attempt to index nil with ‘WaitForChild’”

image

Im confused is this what you mean?

Is this on a server or client script?

And yes, that’s what joyfully and graciously I mean.

from the error code we can see that it is inside serverScriptService, so that means that it is a serverScript

You can’t use LocalPlayer on the Server, only the client, instead use a remote event or something of the sort. (Also, adding to leaderstats on the client doesn’t work because it only shows up on the client, and therefore doesn’t update on the server.)

Correct, I was going to say this but you beat me to it!