Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I add an animation to a table and remove it once its finished?

in my game doors are opened via animations, and there is a pause function which stops everything bar the door animations. Is there a way I can create a table of these animation and then remove them once they have finished?

2 comments

0

What type of animations?

0

Animation objects, roblox animations

2 answers

Since you are using the usual animations (I take it you a loading them into the door model using AnimationControllers), then every time you load an animation, it returns the AnimationTrack.

AnimationTracks have two notable functions: Play() and Stop(). All you need to do is make a table, like so:

local anims = {}

Then add in the animations when you play them:

local anim = controller:LoadAnimation(animationObject)
anim:Play()
table.insert(anims,anim)

Then, when you want to stop the animations:

for _,v in pairs (anims) do
	v:Stop()
end

So:

local anims = {}

function stopPlayingAnims()
	for _,v in pairs (anims) do
		v:Stop()
	end
end

local anim = controller:LoadAnimation(animationObject)
anim:Play()
table.insert(anims,anim)

Hope I helped!

~TDP

2 comments

0

Ooo, it was close, but not quite a pause. And wouldn't that continue to build a table despite stopping?

0

Ah, oops. Just change the '_' to 'key', and remove the value from the table :)

nvm, found out how. For those curious, Local Anim = PathToAnimation local ATrack= ANIMcontroller:LoadAnimation(Anim) ATrack:Play()

local con local stopa con = linktoabool.Changed:connect(function() if pause then ATrack:AdjustSpeed(0) else ATrack:AdjustSpeed(1) end end) stopa = ATrack.Stopped:connect(function() con:disconnect() stopa:disconnect() end)

This discussion is preserved as it was. New answers, comments, and votes are closed.