I had the same problem with the sound in the same tool. But that was with audio, which I fixed. Now it's with the animation which is why I think the same method I used on the other script isnt working.

What the problem is: It plays an animation on activation of the tool, waits, then stops. But if I unequip the item, it continues to play.

what I tried: I tried looking for people with similar problems, creating an if statement (if script.Parent.Unequipped then track:Stop()), destroying it, or equaling it to nil. Not sure what else to do.

here is my code, I tried to point out lines I need help on so you dont have to read the whole thing

local heal = script.Parent -- the tool
-- the animation ID
local cast = Instance.new ("Animation") cast.AnimationId = "http://www.roblox.com/Asset?ID=5207038516"

local debounce = false
heal.Activated:connect (function() --main function	
	local char = heal.Parent
	local track = char.Humanoid:LoadAnimation(cast) --loading the animation
	if debounce then return end
	debounce = true
	track:Play() --plays animation
	wait (7)     --what I think the problem is
	track:Stop()
	if heal.Unequipped then --what I tried (nil, destroy(), stop())
		track = nil
	end
	debounce = false
end)



heal.Unequipped:Connect (function() --What I want the tool to do if it's unequipped
	local char = heal.Parent -- which it does do it, but not while the tool is playing the main function
	local track = char.Humanoid:LoadAnimation(cast)
	track:Stop()
end)

3 comments

0

Is this a local script?

0

wait what am i asking, of course it is

0

Yeah it is. I know there's a way to do it I just don't know how to write it out. I'm trying to find a way to check if the tool is unequipped, then track will stop but this wont work. I know it's an easy fix I just cant figure out how to write the code :/