Hello, why my animation is not stopped when the weapon is destroyed ?
local uis = game:GetService("UserInputService")
local p = game:GetService("Players").LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local Equip_ARI = script:WaitForChild("Equip_ARI")
uis.InputBegan:Connect(function(code, _gp)
if code.KeyCode == Enum.KeyCode.One and not _gp then
local character = p.Character
local humanoid = character:FindFirstChild("Humanoid")
local mWeapon = rs.Events.Inventory.GetMainWeapon:InvokeServer()
if mWeapon == "ARI" then
local isEquipped = rs.Events.Items.GetARIEquipped:InvokeServer()
local EquipAnimTrack_ARI = humanoid.Animator:LoadAnimation(Equip_ARI)
if isEquipped then
character:FindFirstChild("ARI"):Destroy()
rs.Events.Items.SetARIEquipped:FireServer(false)
EquipAnimTrack_ARI:Stop()
else
rs.Events.Items.GiveItem:FireServer("ARI")
rs.Events.Items.SetARIEquipped:FireServer(true)
EquipAnimTrack_ARI:Play()
end
end
end
end)
I used the animator to get the current animations played by the character.
local uis = game:GetService("UserInputService")
local p = game:GetService("Players").LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local Equip_ARI = script:WaitForChild("Equip_ARI")
uis.InputBegan:Connect(function(code, _gp)
if code.KeyCode == Enum.KeyCode.One and not _gp then
local character = p.Character
local humanoid = character:FindFirstChild("Humanoid")
local mWeapon = rs.Events.Inventory.GetMainWeapon:InvokeServer()
if mWeapon == "ARI" then
local isEquipped = rs.Events.Items.GetARIEquipped:InvokeServer()
local EquipAnimTrack_ARI = humanoid.Animator:LoadAnimation(Equip_ARI)
if isEquipped then
rs.Events.Items.RemoveItem:FireServer("ARI")
rs.Events.Items.SetARIEquipped:FireServer(false)
EquipAnimTrack_ARI:Stop()
local tracks = humanoid:FindFirstChildOfClass("Animator"):GetPlayingAnimationTracks()
for i,v in pairs(tracks) do
if v.Name == "Equip_ARI" then
v:Stop()
end
end
else
rs.Events.Items.GiveItem:FireServer("ARI")
rs.Events.Items.SetARIEquipped:FireServer(true)
EquipAnimTrack_ARI:Play()
end
end
end
end)