Why do my running script doesn't work?

Yesterday, my running script worked perfectly, and for some reason, today, all of a sudden, it doesn’t work.

local Player = game.Players.LocalPlayer
	local Character = workspace:WaitForChild(Player.Name)
		local Humanoid = Character:WaitForChild('Humanoid')
		
local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = 'rbxassetid://10526270312'
RAnimation = Humanoid:LoadAnimation(RunAnimation)

Running = false

function Handler(BindName, InputState)
	if InputState == Enum.UserInputState.Begin and BindName == 'RunBind' then
        print("Shift Pressed")
		Running = true
		Humanoid.WalkSpeed = 26
	elseif InputState == Enum.UserInputState.End and BindName == 'RunBind' then
        print("Shift Stopped")
		Running = false
		if RAnimation.IsPlaying then
			RAnimation:Stop()
		end
		Humanoid.WalkSpeed = 16
	end
end

Humanoid.Running:connect(function(Speed)
	if Speed >= 10 and Running and not RAnimation.IsPlaying then
		RAnimation:Play()
		Humanoid.WalkSpeed = 26
	elseif Speed >= 10 and not Running and RAnimation.IsPlaying then
		RAnimation:Stop()
		Humanoid.WalkSpeed = 16
	elseif Speed < 10 and RAnimation.IsPlaying then
		RAnimation:Stop()
		Humanoid.WalkSpeed = 16
	end
end)

Humanoid.Changed:connect(function()
	if Humanoid.Jump and RAnimation.IsPlaying then
		RAnimation:Stop()
	end
end)

game:GetService('ContextActionService'):BindAction('RunBind', Handler, true, Enum.KeyCode.LeftShift)

When I press shift, it perfectly prints “Shift Pressed”. So I do not understand why it shouldn’t change the walkspeed. You guys can ask me more details.

1 Like

Is the Humanoid or Character nil? Try doing this instead

local Character = Player.Character or Player.CharacterAdded:Wait()
1 Like

If this is the part that doesn’t work, the Humanoid doesn’t have an “Idle” state. It’s always Running until another action is done, such as Climbing or Swimming.