I would recommend using a touch event like so (in the server) parented to the tool:
script.Parent.Touched:Connect(function(part)
if part.Parent ~= script.Parent.Parent:WaitForChild("HumanoidRootPart") and part.Parent:WaitForChild("HumanoidRootPart") then
script.Parent:Destroy()
end
end)
the problem now is that once the tool is deleted, the idle tool animation still plays and doesn’t go back to the normal idle animation. This is why I’m asking how could I go about this to be able to stop the idle animation when I don’t have access to it on the server script, nor on the activation function in the client script. I only have it on the equipped function in the client script.
Do you mean the event from the previous script I showed you? because that is in the the server, the activation script that I just showed fires the remote event to that server script.
local AnimationTrack = nil --This later gets set to the animation when the tool is equipped
Tool.Removing:Connect(function()
if AnimationTrack then
AnimationTrack:Stop()
end
end)
You need to load the animation and set a variable outside the equip function to do this
I would provide full code but I’m on mobile right now so
Old post: (for Unequipped)
I forget if LocalScripts run in player.Backpack or not, but if they don’t, either connect the AnimationTrack:Stop() in a Tool.Unequipped event or copy paste the code into a Script and set its run context to Client (So that it can basically run anywhere)
I’d recommend copying code so that it’s easier to explain where edits go.
You could do this after line 7:
local unequipped
local destroyed
destroyed = script.Parent.Destroying:Once(function()
AnimationTrack:Stop()
AnimationTrack = nil
if destroyed and destroyed.Connected then destroyed:Disconnect() end destroyed = nil
if unequipped and unequipped.Connected then unequipped:Disconnect() end unequipped = nil
end)
unequipped = script.Parent.Unequipped:Once(function()
AnimationTrack:Stop()
AnimationTrack = nil
if destroyed and destroyed.Connected then destroyed:Disconnect() end destroyed = nil
if unequipped and unequipped.Connected then unequipped:Disconnect() end unequipped = nil
end)
Solved the problem a different way. I tried many methods and it didn’t seem to work so I tried something different. When the tool is used it would be parented to a folder where anything that enters that folder will destroy it. The reason why I did this instead is because I noticed that it actually stopped the tool idle animation when I put the tool in a different area compared to just destroying it. Not sure why it didn’t work when I was destroying the tool before but it may have something to do with the response time, not sure. But thank you for everyone that tried to help, I appreciate it!