While attacking, if the player unequips the tool, the player will stop attacking but the looping animation will play right after. Tried putting a wait() but if the player is fast enough, it will still play the animation.
Before:
After:
Here is the LocalScript.
local parent = script.Parent
local Handle = parent:WaitForChild("Handle")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- Ensure that the character's humanoid contains an "Animator" object
local Humanoid = character:WaitForChild("Humanoid")
EquipAnim = parent.Animations.Equip
IdleAnim = parent.Animations.Idle
Attack = parent.Animations.Attack
local Equip = Humanoid:WaitForChild("Animator"):LoadAnimation(EquipAnim)
local Idle = Humanoid:WaitForChild("Animator"):LoadAnimation(IdleAnim)
local Attack = Humanoid:WaitForChild("Animator"):LoadAnimation(Attack)
CanDmg = false
Can = true
cd = 0.44
parent.Unequipped:Connect(function()
Unequip()
end)
function Unequip()
if Attack.IsPlaying then
Attack:Stop()
end
if Idle.IsPlaying then
Idle:Stop()
end
end
parent.Equipped:Connect(function()
Handle.Equip:Play()
Equip:Play()
wait()
Idle:Play()
end)
parent.Activated:Connect(function()
if Can == true then
Can = false
Humanoid.JumpPower = 0
if Equip.IsPlaying then
Equip:Stop()
end
if Idle.IsPlaying then
Idle:Stop()
end
Attack:Play()
wait(.36)
Humanoid.JumpPower = 60.999
Idle:Play()
wait(cd)
Can = true
end
end)