Simple script that improves quality of life when loading animations for me

this script assumes that

your script is under the animator.
an animation object is under the script.
the animation object’s id is empty.
(change accordingly)

local animationids = {}

local animation = script.Animation

local animator = script.Parent

local animationtracks = {}

for i, v in pairs(animationids) do
	animation.AnimationId = v
	local animationtrack = animator:LoadAnimation(animation)
	table.insert(animationtracks, animationtrack)
end

print(table.unpack(animationtracks)) --this is a must or else you wont know the order of your animation

--if you know table.unpack, you should be able to do the last part but if you dont
--you should go learn how it works
3 Likes

i have made one simple terrible mistake

this is the new script that looks cleaner to me (its nothing much)

local animationids, animation, animator, animationtracks = {
--the order of animation when you unpack is the order of the ids
}, script.Animation, script.Parent, {}

for i, v in pairs(animationids) do
	animation.AnimationId = v
	local animationtrack = animator:LoadAnimation(animation)

	table.insert(animationtracks, animationtrack)
end

local _ = table.unpack(animationtracks)

let me show you an example of what i mean by “order”

local animationids, animation, animator, animationtracks = {
	"http://www.roblox.com/asset/?id=180435571", --idle animation id
	"http://www.roblox.com/asset/?id=125750702", --jump animation id
	"http://www.roblox.com/asset/?id=180426354", --run animation id
	"http://www.roblox.com/asset/?id=178130996"  --sit animation id
}, script.Animation, script.Parent, {}

for i, v in pairs(animationids) do
	animation.AnimationId = v
	local animationtrack = animator:LoadAnimation(animation)

	table.insert(animationtracks, animationtrack)
end

local idle, jump, run, sit = table.unpack(animationtracks) -- as you can see here
--down here you could do some testing if you want
idle:Play()

wait(2.5)

jump:Play()

wait(2.5)

run:Play()

wait(2.5)

sit:Play()
1 Like