Script that gradually increases a Leaderboard value over time isn't working

I am making a Leaderboard which includes a Seconds Played system which obviously increases a “Seconds Played” value on said Leaderboard by 1 every second. I’m also making a Money value which increases by 10 every second.

I have programmed the Leaderboard and the script used to increase the values. I did it how I thought it was meant to work, but it didn’t for some reason as to which I am completely clueless of.

The Leaderboard’s code can be found following this sentence:

game.Players.PlayerAdded:Connect(function(plr)
	local ls = Instance.new("Folder")
	ls.Name = "leaderstats"
	ls.Parent = plr
	
	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Parent = ls
	money.Value = 100
	
	local level = Instance.new("IntValue")
	level.Name = "Levels"
	level.Parent = ls
	
	local tp = Instance.new("IntValue")
	tp.Name = "Seconds Played"
	tp.Parent = ls
end)

The Value Increaser’s code can be found following this sentence:

while wait(1) do
	game.Players.PlayerAdded:Connect(function(plr)
		local tpv = game.Players.plr.leaderstats["Seconds Played"].Value
		local mv = game.Players.plr.leaderstats.Money.Value
		tpv = tpv + 1
		mv = mv + 10
	end)
end

The ancestry of the Scripts is in this photo:
image

2 Likes

LocalScripts don’t run in ServerScriptService.

1 Like

Is the increaser code inside of the SP/M_Handler local script? It may be that the localscript is making changes on the client, however your leaderboard doesn’t actually detect said change since it is on the client.

1 Like

I changed it to a Script and it still isn’t working

code
game.Players.PlayerAdded:Connect(function(plr)
	local ls = Instance.new("Folder")
	ls.Name = "leaderstats"
	ls.Parent = plr
	
	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Parent = ls
	money.Value = 100
	
	local level = Instance.new("IntValue")
	level.Name = "Levels"
	level.Parent = ls
	
	local tp = Instance.new("IntValue")
	tp.Name = "Seconds Played"
	tp.Parent = ls
	
	while true do task.wait(1)
		tp.Value += 1
		money.Value += 10
	end
end)

remove the “SP/M_Handler” script, and change the leaderstats script to the above code

also just a suggestion, make your variables full words

Ok thanks, I’ll try it out right now

Just found out it works, thanks so much! I’m going to modify it a bit now, again, thanks!

And I have a question: Could you help me on another one of my scripts? I have a DevForum post on it so it would be easier to help.