Steps keep showing as 100

Hello, I want to calculate whenever the player steps and when they get down to 0, they are unable to move. I will get to the player not being able to move after I find out whats causing this problem. So basically the problem is is that the script detects when its moving but only once, so it doesn’t count below 99. How would I make it so that it doesn’t do that?
Thanks.

Here is my current code:

local player = game.Players.LocalPlayer
local Humanoid = player.Character:WaitForChild("Humanoid")
local steps = tonumber(player.PlayerGui.StepsGUI.TextLabel.Text)
print(steps)

while wait() do
	print(steps)
	print("made loop")
	if steps ~= 0 then
		print("checked")
		if Humanoid.MoveDirection ~= Vector3.new(0, 0, 0) then
			print("hum is moving")
			local new = steps-1
			print("minus step")
			local text = tostring(new)
			print("revert to string")
			player.PlayerGui.StepsGUI.TextLabel.Text = text
			print("changed text")
		end
	end
end

The print() is for me to find out if it stops and doesn’t give an error in the middle of the script to see where it stopped.

The way youre calculating the steps is inaccurate but heres the fixed script:

local player = game.Players.LocalPlayer
local Humanoid = player.Character:WaitForChild("Humanoid")
local steps = player.PlayerGui.StepsGUI.TextLabel
print(steps.Text)

while wait() do
	print(steps)
	print("made loop")
	if steps ~= 0 then
		print("checked")
		if Humanoid.MoveDirection ~= Vector3.new(0, 0, 0) then
			print("hum is moving")
			local new = tonumber(steps.Text)-1
			print("minus step")
			local text = tostring(new)
			print("revert to string")
			player.PlayerGui.StepsGUI.TextLabel.Text = text
			print("changed text")
		end
	end
end
1 Like

Thanks, what would be a more accurate way?

Don’t use wait(). If you’re on a LocalScript, use RunService.RenderStepped to update every frame. If you wish to still have an interval, use task.wait() as it is guaranteed to continue after the given time, unlike the deprecated wait().

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.