Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My sprint animation script for my Roblox game needs some fixing, could anybody help?

I need help fixing my sprint script, it has an animation that plays when you hold the sprint keybind. I need help with stopping the animation when the player jumps, climbs, is doing the idle and swimming. Here is the current script, please alter it to fix these problems in the comments:

UIS.InputBegan:connect(function(input)
 if input.KeyCode == Enum.KeyCode.LeftShift then
  Character.Humanoid.WalkSpeed = 35
  local Anim = Instance.new('Animation')
  Anim.AnimationId = 'rbxassetid://04942942286'
  PlayAnim = Character.Humanoid:LoadAnimation(Anim)
  PlayAnim:Play()
 end
end)

UIS.InputEnded:connect(function(input)
 if input.KeyCode == Enum.KeyCode.LeftShift then
  Character.Humanoid.WalkSpeed = 16
  PlayAnim:Stop()
 end
end)

1 answer

This script should work but make sure you put it in a local script inside starter player

UIS.InputBegan:connect(function(input)
 if input.KeyCode == Enum.KeyCode.LeftShift then
  Character.Humanoid.WalkSpeed = 35
  local Anim = Instance.new('Animation')
  Anim.AnimationId = 'rbxassetid://04942942286'
  PlayAnim = Character.Humanoid:LoadAnimation(Anim)
  PlayAnim:Play()
 end
end)

UIS.InputEnded:connect(function(input)
 if input.KeyCode == Enum.KeyCode.LeftShift then
  Character.Humanoid.WalkSpeed = 16
  PlayAnim:Stop()
 end
end)

local character = script.Parent 
 
local humanoid = character:WaitForChild("Humanoid")
 
humanoid.Climbing:Connect(function(speed)
	print("Climbing speed: ", speed)
end)
 
humanoid.FallingDown:Connect(function(isActive)
Character.Humanoid.WalkSpeed = 16
	print("Falling down: ", isActive)
end)
 
humanoid.Jumping:Connect(function(isActive)
Character.Humanoid.WalkSpeed = 16
	print("Jumping: ", isActive)
end)
 
humanoid.Swimming:Connect(function(speed)
Character.Humanoid.WalkSpeed = 16
	end)

if humanoid.MoveDirection == Vector3.new(0, 0, 0) 
and humanoid:GetState() ~= Enum.HumanoidStateType.Jumping 
and humanoid:GetState() ~= Enum.HumanoidStateType.FreeFall then
Character.Humanoid.WalkSpeed = 16
    
end
end

6 comments

0

Thanks, I really appreciate it.

0

i misread the op question, but what you posted isn't going to do what he asked.

0

How

0

it only checks the humanoid state once, and it doesn't stop the animation. there is too much going on there.

0

Ok and

0

and it won't work? you're downvoting my post because i downvoted yours. i only did it because your script is incorrect.

This discussion is preserved as it was. New answers, comments, and votes are closed.