Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This is a Stats script i have 2 Values why doesn't it add value to the Stats?

So this is an obstacle course game and i am trying to make it so that every 20 stages you complete / gain in the statistics wise of course, you get +1 Skips in the stats place as well.

Stage = game.Players.LocalPlayer.PlayerStats:WaitForChild("Stage")
Skips = game.Players.LocalPlayer.PlayerStats:WaitForChild("Skips")

if Stage.Value >= 10 then
	Skips.Value = 1
	elseif Stage.Value >= 20 then
		Skups.Value = 2
end

2 answers

✓ Accepted answer

There are a few things wrong

First of all, if the game is Filtering Enabled then Local Scripts really can't affect leaderstats of any kind. Also, this obviously won't do anything because the script only runs once, and doesn't get updated. To update the script, you could use a Loop or the Changed event. I suggest the Changed event. I also suggest using a regular script, and getting the players with the PlayerAdded event.

Example,

-- In a regular script in Server Script Service

game.Players.PlayerAdded:connect(function(plr)
	local PlayerStats = plr:WaitForChild("PlayerStats")
	local Stage = PlayerStats:WaitForChild("Stage")
	local Skips = PlayerStats:WaitForChild("Skips")
	
	Stage.Changed:connect(function()
		if Stage.Value >= 10 then
			Skips.Value = 1
		elseif Stage.Value >= 20 then
			Skips.Value = 2
		end
	end)
end)
You also made a typo after the elseif

Doing the math

All we have to do is divide Stage by 10 and use the math.floor function to round it down.

-- In a regular script in Server Script Service

game.Players.PlayerAdded:connect(function(plr)
	local PlayerStats = plr:WaitForChild("PlayerStats")
	local Stage = PlayerStats:WaitForChild("Stage")
	local Skips = PlayerStats:WaitForChild("Skips")
	
	Stage.Changed:connect(function()
		Skips.Value = math.floor(Stage.Value/10)
	end)
end)
Fixed typo

Let me know if you have any problems, or if the script isn't working for you.

Good Luck!

If I helped, please don't forget to accept my answer.
Stage = game.Players.LocalPlayer.PlayerStats:WaitForChild("Stage")
Skips = game.Players.LocalPlayer.PlayerStats:WaitForChild("Skips")

if Stage.Value >= 10 then
	Skips.Value = 1
elseif Stage.Value >= 20 then
	Skips.Value = 2
end

You simply misspelled "Skips" in line 7. In your original code, you put "Skups".

1 comment

0

Well the first one doesn't work either for some reason so it can't be that and i want it to be coded so every 10 Stages you gain 1 Skip so it would be 10,20,30,40,50,60,70,80,90,100 1,2,3,4,5,6,7,8,9,10

This discussion is preserved as it was. New answers, comments, and votes are closed.