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

How can I have animation 1 interrupt animation 2?

I have two animations. I have a gun hold animation, and a gun shoot animation. I'm trying to have the gun hold animation play, and then when the shoot animation is called, it plays over the hold animation.

I searched for solutions but honestly it's a tricky question to find the words for.

local Players = game:GetService("Players")
local gunequipped = false
local WeaponTool = script.Parent.Pistol
local player = Players.LocalPlayer

local character = player.Character
if not character or not character.Parent then
	character = player.CharacterAdded:Wait()
end

local char = character
print(char.Name)
print(character.Name)
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")



---------------- Pistol Hold anim -----------------------
local HoldGunAnimation = Instance.new("Animation")
-- Set its "AnimationId" to the corresponding animation asset ID
HoldGunAnimation.AnimationId = "rbxassetid://7225805475"
local HoldGunAnimationTrack = animator:LoadAnimation(HoldGunAnimation)
HoldGunAnimationTrack.Priority = Enum.AnimationPriority.Action
-----------------------------------------------------------------

---------------- Glock Shoot anim--------------------------
local GlockShootAnimation = Instance.new("Animation")
-- Set its "AnimationId" to the corresponding animation asset ID
GlockShootAnimation.AnimationId = "rbxassetid://7244252732"
local GlockShootAnimationTrack = animator:LoadAnimation(HoldGunAnimation)
GlockShootAnimationTrack.Priority = Enum.AnimationPriority.Action
-----------------------------------------------------------------


-------------------------------------------------------------------------------------------





script.Parent.Equipped:Connect(function()
	gunequipped = true
	shiftLock(true)
	local M6D = Instance.new("Motor6D")
	M6D.Parent = char.UpperTorso
	print(M6D.Parent)
	M6D.Name = "ToolGrip"
	print(M6D.Name)
	game.ReplicatedStorage.ConnectM6D:FireServer(WeaponTool.BodyAttach)
	char.UpperTorso:FindFirstChild("ToolGrip").Part0 = char.UpperTorso
	char.UpperTorso:FindFirstChild("ToolGrip").Part1 = WeaponTool.BodyAttach


HoldGunAnimationTrack:Play()




	
end)

script.Parent.Unequipped:Connect(function()
	gunequipped = false
	print("Unequipped")
	game.ReplicatedStorage.DisconnectM6D:FireServer()
	shiftLock(false)
HoldGunAnimationTrack:Stop()
end)





-- shoot anim --
local be = script.Parent.Remotes:WaitForChild("~~~~Event Name~~~")


local function AnimatorEvent(AnimType)
	print(AnimType)
	print("ANIMATION STARTING")
	if AnimType == "ShootAnim" then
		HoldGunAnimationTrack:Stop()
		GlockShootAnimationTrack:Play()
		GlockShootAnimationTrack.Stopped:wait()
		HoldGunAnimationTrack:Play()
	end
end
be.Event:Connect(AnimatorEvent)

Any insight would help! Thanks if you've read this far!

1 comment

0

You will need to use the animation priority. Try setting it to something higher like 'Action'.

2 answers

Set the shooting animation's priority to be higher etc movement

2 comments

0

Exactly. Animations have a 'tier' system. If animation A has a higher animation priority than animation B, animation A will play over top of animation B.

0

I've been trying to use animation priority to fix this, however it seems to have no result (I changed the hold animation to idle and the shoot animation to action)

I made a pretty stupid mistake. The locals for the animations were mixed up. It's as simple as that. Remember to always check your code 100 times!

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