I’m trying to make a knife for my new game but something went terribly wrong, the knife animations plays after I unequipped the knife, can anyone help fix this?
--Variables
wait()
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local PlayingAnimation = nil
local Activated = false
local Equipped = false
local canUse = false
local StartTick = tick()
local Activetick = tick()
local Mouse = Player:GetMouse()
--Script:
--repeat wait() until Character ~= nil
local Animations = {
Charge = {
Animation = Character.Humanoid:LoadAnimation(script.Parent:WaitForChild("Charge")),
Duration = 1
},
Idle = {
Animation = Character.Humanoid:LoadAnimation(script.Parent:WaitForChild("Idle")),
},
ChargeHold = {
Animation = Character.Humanoid:LoadAnimation(script.Parent:WaitForChild("ChargeHold")),
},
Stab1 = {
Animation = Character.Humanoid:LoadAnimation(script.Parent:WaitForChild("Stab1")),
Duration = .55
},
Stab2 = {
Animation = Character.Humanoid:LoadAnimation(script.Parent:WaitForChild("Stab2")),
Duration = .8
},
Equip = {
Animation = Character.Humanoid:LoadAnimation(script.Parent:WaitForChild("Equip")),
Duration = 1
},
EquipSlow = {
Animation = Character.Humanoid:LoadAnimation(script.Parent:WaitForChild("EquipSlow")),
Duration = 1,
},
}
wait("loaded")
Tool.Equipped:Connect(function()
print("Equipped Knife")
Equipped = true
PlayingAnimation = Animations.Equip
PlayingAnimation.Animation:Play()
StartTick = tick()
repeat wait() until (tick() - StartTick) >= PlayingAnimation.Duration
PlayingAnimation.Animation:Stop()
PlayingAnimation = Animations.Idle
PlayingAnimation.Animation:Play()
canUse = true
print("yes")
end)
Tool.Activated:Connect(function()
if Equipped then
if canUse then
Activated = true
Activetick = tick()
PlayingAnimation.Animation:Stop()
PlayingAnimation = Animations.Charge
PlayingAnimation.Animation:Play()
repeat wait() until (tick() - Activetick) >= .25 or Activated == false
if Activated and PlayingAnimation == Animations.Charge and canUse then
PlayingAnimation.Animation:Stop()
PlayingAnimation = Animations.ChargeHold
PlayingAnimation.Animation:Play()
end
end
end
end)