I have now spent 3, 1/2 hours trying to create my script from scratch. My main problem is that when I spam the tool, the second animation that plays will get stuck and play forever, even after the tool has been unequipped. Another issue is if I were to play both animations at the same time, the second one would overlap the first one for a split second even if the Action level is level 4.
If anyone can PLEASE help me create or give me help on how I can fix it so the tool animation doesnât get stuck when spammed equip/unequipped fast, thatâd be so helpful.
This is what I currently have:
local tool = script.Parent
local anim = Instance.new("Animation")
local anim2 = Instance.new("Animation")
anim.AnimationId = 'https://www.roblox.com/Assest?ID=16959719719'
anim2.AnimationId = 'https://www.roblox.com/Assest?ID=16942938568' --Id here
local track
local track2
tool.Equipped:Connect(function()
track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action2
track:Play(0.6)
tool.Handle.Transparency = 1
wait(0.1)
tool.Handle.Transparency = 0
track.Stopped:Wait()
tool.Main.Enabled = true
track2 = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(anim2)
track2.Priority = Enum.AnimationPriority.Action
track2:Play(0.2)
end)
tool.Unequipped:Connect(function()
if track then
track:Stop()
track:Destroy()
track = nil
end
if track2 then
track2:Stop()
track2:Destroy()
track2 = nil
end
end)
The issue is with the track2, for some reason if I were to spam the tool that animation would break and continue to stay after I unequip the tool. Iâve tried to do IsPlaying but it doesnât seem to fix it.
The issue with your second animation playing indefinitely is caused by that âwaitâ in the equip event. What happens is that two events happen at the same time if you spam the tool. Eventually the unequip event is fired before an equip event is finished, therefore keeping the animation on forever.
The simplest thing that comes to my mind rn (without having to change the code) is to remove the looping animation setting from roblox animation editor (i guess thatâs the case, if itâs not lmk)
Add some sort of animation handler: keep track of the track (sorry for the wordplay) loaded into the humanoid so that you have full control over it. Something like this at the start of your code:
local anim = Instance.new("Animation")
local char = script.Parent.Parent // From what I can see from your code
// First Animation
anim.AnimationId = 'https://www.roblox.com/Assest?ID=16959719719'
local track1 = char.Humanoid:LoadAnimation(anim)
// Second one
anim.AnimationId = 'https://www.roblox.com/Assest?ID=16942938568'
local track2 = char.Humanoid:LoadAnimation(anim)
Then you use those two variable in the rest of the code without checking for their validity or loading (so just :play() and :stop())
If I play both of them at the same time, when I equip the tool there is a split second that the Idle animation plays before the equip, no matter the action level, making the animations look weird. Thatâs why there is a wait between them both.
didnât say to play them at the same time, just not to load them during the event, your code would look something like this
local tool = script.Parent
local anim = Instance.new("Animation")
local char = script.Parent.Parent // From what I can see from your code
// First Animation
anim.AnimationId = 'https://www.roblox.com/Assest?ID=16959719719'
local track1 = char.Humanoid:LoadAnimation(anim)
// Second one
anim.AnimationId = 'https://www.roblox.com/Assest?ID=16942938568'
local track2 = char.Humanoid:LoadAnimation(anim)
track2.Priority = Enum.AnimationPriority.Action
tool.Equipped:Connect(function()
track1:Play(0.6)
tool.Handle.Transparency = 1
wait(0.1)
tool.Handle.Transparency = 0
track1.Stopped:Wait()
tool.Main.Enabled = true
-- Put a condition checking if the tool is equipped here, if it is then play it
track2:Play(0.2)
end)
tool.Unequipped:Connect(function()
track1:Stop()
track2:Stop()
end)
add a if script.Parent.Parent:FindFirstChild("Humanoid") then at the top of the code (the script is present both in the player backpack and in the character model, if i do remember correctly, this allows you to filter out the first possibility)