here is the script:

local InputService = game:GetService("UserInputService")
local Running = false
local humanoid = script.Parent.Humanoid
local moving
local WalkAnim = script.Parent.Animate.walk.WalkAnim.AnimationId
local RunAnim = game.Lighting.Anim
local RunAnimLoaded = humanoid:LoadAnimation(RunAnim)
local Running = false

humanoid.Running:connect(function(speed)
	if speed > 0 then moving = true
		humanoid.Parent["Left Leg"].BrickColor = BrickColor.new("Really red") 
	elseif speed < 1 then
		moving = false
		humanoid.Parent["Left Leg"].BrickColor = BrickColor.new("Fossil")
	end
end)

InputService.InputBegan:connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift then
		if Running == false then
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25
			Running = true
			if moving == true then
				RunAnimLoaded:Play()
			elseif moving == false then
				game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
				Running = false
				RunAnimLoaded:Stop()
			end
	else
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
			Running = false
			RunAnimLoaded:Stop()
			end
	end
end)

when i stop walking my character is kind off still playing the animation, until i press LeftShift again. Whats happening?

4 comments

0

Try using some print statements to debug the code. Put a print to see what speed is in the Humanoid.Running:Connect function.

1

This is not an answer but never ever use mouse.KeyDown, it is deprecated and will be broken in future updates as you should use UserInputService.InputBegan, and why not try using coroutine thread and while true do to check if moving is true or not.

0

The reason why it never stops the animation because you checked moving == true for a single time, using a loop and coroutine thread will do the work as what I said before.

0

how / where should i use the loop and coroutine?