Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My animation script isn't working as intended. How do I fix?

Asked by 4 years ago

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)

0
Is this a local script? MrCatDoggo 213 — 4y
0
wait what am i asking, of course it is MrCatDoggo 213 — 4y
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 :/ Telasim0 6 — 4y

Answer this question