Stop playing animation when tool destroyed

This is really confusing because when i did a similar situation as you, it worked. Try loading the animation on the humanoid instead of the animator, because that was pretty much the only difference between my experiment and your code i think.

humanoid:LoadAnimation(holdingbasketAnimation)

I changed
image
to
image
but still nothing :cry:

It could be the Prompt script that’s causing an issue with detecting the tool?

Is the tool script a local script? Because it seems that you defined the player with

game.Players.LocalPlayer

Which you shouldn’t do in a normal script. And even if it is a local script, the server wouldn’t be able to detect the animation because you ran it locally so you should change it to a normal script.
Do this:

local holdingbasketAnimation = script.holdingbasket
local holdingbasket = nil

tool.Equipped:Connect(function()
    holdingbasket = tool.Parent.Humanoid:LoadAnimation(holdingbasketAnimation)
 
    holdingbasket.Priority = Enum.AnimationPriority.Action
	holdingbasket.Looped = true

	holdingbasket:Play()
end)

tool.Unequipped:Connect(function()
    holdingbasket:Stop()
end)

The script in the tool is a local script, but the part with the proximity prompt has a regular script in it.

image

This is the part with the prompt:
image

So you want me to change the localscript in the tool to a regular script? Is that safe?

Also “Tool is” underlined for me:

You forgot to stop the animation before the tool is destroyed.

1 Like

You need to define tool

local tool = script.Parent

If you use a local script then it wont work because you run the animation locally so the server script cant “see” that the animation is playing.

Omg that fixed it! Thank you!! Could you perchance explain what the difference is between Localscript and script? Why does script have the ability to detect the animation?

Because local scripts only run on the client (The players computer). it doesn’t run on the server. for example if you tried to kill someone with a local script, then the player would only die on your screen. If you change something on a local script then that change would only effect your computer and not the server running the game. If a cheater changed their speed to 50, their computer will allow it so they can run fast, but the server still registers that the player has 16 (default speed) because the cheater changed a property on their computer and not on the server.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.