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

How would I script making an animation stop for another to start?

My problem is that I made a sprint key , but when I jump while the sprint key is active, the the jump animation does not happen. I wanna learn how to fix this so that no animation overlays the other. Practically I wanna know how to stop and start in between animations. Here's my code to understand more of what I mean.

local UIS = game:GetService('UserInputService')

local Player = game.Players.LocalPlayer
local Character = Player.Character
local hum = game.Workspace:WaitForChild("Humanoid")


UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
 if input.KeyCode == Enum.KeyCode.LeftControl  then
  local Anim = Instance.new('Animation')
  Anim.AnimationId = 'rbxassetid://5150687024'
  PlayAnim = Character.Humanoid:LoadAnimation(Anim)
  PlayAnim:Play()
   Character.Humanoid.WalkSpeed = 50
 end
end)

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

1 answer

This answer is what I think (might work)

This is yours:

local UIS = game:GetService('UserInputService')

local Player = game.Players.LocalPlayer local Character = Player.Character local hum = game.Workspace:WaitForChild("Humanoid")

UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35. if input.KeyCode == Enum.KeyCode.LeftControl then local Anim = Instance.new('Animation') Anim.AnimationId = 'rbxassetid://5150687024' PlayAnim = Character.Humanoid:LoadAnimation(Anim) PlayAnim:Play() Character.Humanoid.WalkSpeed = 50 end end)

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

This is what I think you should do:

local UIS = game:GetService('UserInputService')

local Player = game.Players.LocalPlayer local Character = Player.Character local hum = game.Workspace:WaitForChild("Humanoid")

UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35. if input.KeyCode == Enum.KeyCode.LeftControl then local Anim = Instance.new('Animation') Anim.AnimationId = 'rbxassetid://5150687024' PlayAnim = Character.Humanoid:LoadAnimation(Anim) PlayAnim:Play() Character.Humanoid.WalkSpeed = 50 end end)

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

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