When the tool is destroyed/removed from the player, the tool animation kept going. How do I fix this problem?
Here’s the video although its self-explanatory.
Here’s the LocalScript -
local anims = {script.Parent.Hold}
local loadedAnims = {}
local tool = script.Parent
local animator
tool.Equipped:Connect(function(mouse)
animator = plr.Character:WaitForChild("Humanoid"):WaitForChild("Animator")
if not loadedAnims[1] then
loadedAnims[1] = animator:LoadAnimation(anims[1])
end
loadedAnims[1]:Play()
end)
tool.Unequipped:Connect(function()
loadedAnims[1]:Stop()
end)
Here’s the script inside the Part that destroys the tool when touched:
local Restock = script.Parent
Restock.Touched:Connect(function(Obj)
if Obj.Parent.Name == "Box" and Obj.Parent:IsA("Tool") then
local PLAYER_OBJECT = Players:GetPlayerFromCharacter(Obj.Parent.Parent)
local tool = Obj:FindFirstAncestorWhichIsA("Tool")
if tool and tool.Name == "Box" then
tool:Destroy()
end
end
end)
I’ve found a fix to this problem. Before destroying the tool, let the player unequip the tool and add a bit of delay before destroying it. Case solved!
Do keep in mind that, on the server-side, the Tool still exists but because of FilteringEnabled this change isn’t communicated to the server but Animations are replicated.
People were mostly over-complicating the fix in this thread, just handle it server-sided as it has the most authority and it replicates to all Clients.