Detecting Idle and Speed not working as expected

  1. What do you want to achieve?
    I want to make it so if the player starts running the walkspeed of the player starts increasing until it reaches 28. But if the player’s movedirection is less than or equal to 0 then it resets the walkspeed of the player back to 10 (10 is the default walkspeed I want for the player when it starts walking.)

  2. What is the issue?
    There are no errors in the output. But when it reaches up to 28 it keeps adding 4 to it. And when the player stops walking it won’t go back to the slowspeed which is 10.

local player = game.Players.LocalPlayer
local Character = player:FindFirstChild("Character")
local humanoid = player.Character:FindFirstChild("Humanoid")

local slowspeed = 10 --starting speed

local addup = 4

local limitedspeed = 28

--		if humanoid:ChangeState() == Enum.HumanoidStateType.Running and humanoid.MoveDirection >= slowspeed then
--			repeat wait(0.1)
--				print("hello")
--				humanoid.WalkSpeed = humanoid.WalkSpeed +4 --adds four everytime
--			until humanoid.WalkSpeed == limitedspeed --limited speed of car
--		elseif humanoid:GetState() == Enum.HumanoidStateType.None or humanoid.MoveDirection <= slowspeed then
--			humanoid.WalkSpeed = slowspeed --goes back to slowspeed
--		end

	if Speed > 0.75 and humanoid:GetState() == Enum.HumanoidStateType.Running then
			humanoid.WalkSpeed = humanoid.WalkSpeed + addup
		until humanoid.WalkSpeed == "28"
		humanoid.WalkSpeed = limitedspeed
		Speed = 0
	elseif humanoid.MoveDirection.Magnitude <= 0 and Speed == 0 and humanoid:GetState() ~= Enum.HumanoidStateType.Running then
		humanoid.WalkSpeed = slowspeed

Also I did “28” with speechmarks because I was trying many ways to detect the walkspeed when it reaches to 28.

Try making it hum.Walkspeed >= 28?

1 Like

It’s kind of working. But now it says that Line 27 is the problem. “attempt to compare string <= number”. And it keeps adding 28 to the number again and won’t stop until it reaches 28 unfortunetaly.

1 Like

Ditch the quotations and you should be good.

1 Like

WalkSpeed is a number, so do:

   humanoid.WalkSpeed += addup
until humanoid.WalkSpeed >= limitedspeed
1 Like

Yeah I just noticed I needed to do that Lol. Thank you for the help though, it’s working!

1 Like