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

How do I delete an animation after it's played?

Asked by 4 years ago

I am trying to delete the animation at the end when it gets stopped, but I am having trouble with that, I've tried Instance:Remove with a few variations but each has fed me an error.

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Script = Character:WaitForChild("Animate")

local debounce = false
    script.Parent.MouseButton1Click:Connect(function(clicked)
        if not debounce then
            debounce = true
            player.Character.Animate.Disabled = true
            local Animation = Instance.new("Animation")
            Animation.AnimationId = "rbxassetid://5035220879"
            Animation.Parent = player.Character
            Animate = Humanoid:LoadAnimation(Animation)
            Animate:Play()
        else
            Animate:Stop()
            debounce = false
            player.Character.Animate.Disabled = false
    end
end)

1 answer

Log in to vote
0
Answered by
zadobyte 692 Moderation Voter
4 years ago

I'm sure you can just do

Animate:Destroy()

whenever you need to, to get rid of the Animation when it's over. Not sure why :Stop() isn't enough for that but whatever you gotta do, you gotta do.

Ad

Answer this question