Humanoid:GetState() not working?

Hello! I’m trying to make a system where if you run, you get more walkspeed every second. For some reason, this is not working.

local player = game.Players.LocalPlayer
local hum = player.CharacterAdded:Wait():WaitForChild("Humanoid")
local speed = hum.WalkSpeed

while wait(1) do
	if hum:GetState() == Enum.HumanoidStateType.Running then
		speed = speed +1

Thank you!

What is the script? LocalScript. Any errors?

Try using Humanoid:StateChanged(), a function, instead of a while loop. And instead of Humanoid.Running, use its MoveDirection. The former only fires when the speed changes not when it stays constant even while running.

if hum.MoveDirection.Magnitude > 0 then
    --they're moving
1 Like

I would first suggest doing this on the server
And calling characteradded:wait() is used incorrectly


To define the humanoid

Nope, no errors.


I tried doing that but that only runs, when the player stops running and starts running again.

I will try using MoveDirection, thank you!

There is a chance that the player’s character is present when the script is ran. It’d be safer to do:

local character = player.Character or player.CharacterAdded:Wait()
local hum = character.Humanoid