Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I have animation 1 interrupt animation 2?

Asked by
mcox6 5
3 years ago

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!

0
You will need to use the animation priority. Try setting it to something higher like 'Action'. Soban06 410 — 3y

2 answers

Log in to vote
2
Answered by 3 years ago

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

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. appxritixn 2235 — 3y
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) mcox6 5 — 3y
Ad
Log in to vote
0
Answered by
mcox6 5
3 years ago

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!

Answer this question