I’m trying to make a tool animation but it’s not working properly, if I click nothing happens but when I unequip the tool the animation plays. Does anyone know why and how to fix this??
local Tool = script.Parent
local Animation = Tool.Animation
local canChop = true
Tool.Activated:Connect(function()
local Character = Tool.Parent
local Humanoid = Character.Humanoid
local AnimationTrack = Humanoid.Animator:LoadAnimation(Animation)
AnimationTrack.Priority = Enum.AnimationPriority.Action -- put it here
if canChop == true then
AnimationTrack:Play()
canChop = false
script.Parent.CanDamage.Value = true
wait(AnimationTrack.Length)
script.Parent.CanDamage.Value = false
canChop = true
end
end)
First thing: put in some print statements. There might be some weird reason that the event isn’t firing.
Then, maybe try setting the animation priority in the animation editor?
Or, alternatively, pre-load the animation by putting this code:
local Character = Tool.Parent
local Humanoid = Character.Humanoid
local AnimationTrack = Humanoid.Animator:LoadAnimation(Animation)
AnimationTrack.Priority = Enum.AnimationPriority.Action -- put it here
before the Tool.Activated event.
If that’s not the case, then I might look into it further - I haven’t tested it myself.
Edit: I recently made a similar system with a staff, and didn’t have this problem. If you want to see its code, then just let me know.
I tried modifying the script to this however it’s still not working.
wait(game.Loaded)
local Tool = script.Parent
local Animation = Tool.Animation
local canChop = true
if Tool.Parent.Parent:IsA("Player") then
Character = Tool.Parent.Parent.Character
else
Character = Tool.Parent
end
local Humanoid = Character:WaitForChild("Humanoid")
local AnimationTrack = Humanoid.Animator:LoadAnimation(Animation)
AnimationTrack.Priority = Enum.AnimationPriority.Action
Tool.Activated:Connect(function()
if canChop == true then
AnimationTrack:Play()
canChop = false
script.Parent.CanDamage.Value = true
wait(AnimationTrack.Length)
script.Parent.CanDamage.Value = false
canChop = true
end
end)
Can you upload the model to Roblox and send me the link?
Also, does the script even run? Whenever I use game.Loaded or game:IsLoaded(), it just waits forever and doesn’t run anything.