A script for testing animations

Provide an overview of:

  • What does the code do and what are you not satisfied with:

Code works pretty well, and i am pretty much satisfied with it. But i would like to know if there any better ways of doing it!
Code was designed by me from scratch for animation testing.
How does it work? you just put id of an animation in the table and it will load it. (Game will also need to have pre-made dummies in the special workspace folder , dummies must have a number in dummy’s name)

  • How (specifically) do you want to improve the code?:

I was wondering if there any ways to make it less performance usage and more professional looking and working of course!
(i am also wondering, if it’s possible for this script to work in the local scripts.)

Additional Info: Script’s parent is a pre-made workspace folder, script’s type: is a server side one.

--[[Made by @XGoogster ! :D

SETTING UP:

Put this script in a folder where your test dummies are.
(if you do not have it then create it and put your test dummies there, do not forget to add numbering to the end of their names.)



]]
local animation_fortests = {[1] = 10884161872} --type your ids here!

local folder_name = "fortests" --type your's folder name here!

--[[
WARNING! 
Be careful exploring anything down there if you are not an experienced user! 
You might break the whole script by editing something on accident.
]]

local folder = workspace:WaitForChild(folder_name) 

local debris = game:GetService("Debris")

local function load_anims(num)

		for i, v in pairs(folder:GetChildren()) do
			
		if v:IsA("Model") and tonumber(string.match(v.Name, "%d+")) == num then
			
			--ignore prints:
			
--print("works")
			
				
				print(num)
			
			--print(animation_fortests[num])
			
				local id = "rbxassetid://"..animation_fortests[i]
		
--print(id)
				
				local hum = v:FindFirstChild("Humanoid")
				
				local animation = Instance.new("Animation")
				animation.AnimationId = id
				animation.Parent = hum
			

				local load_anim = hum:LoadAnimation(animation)
			
			if load_anim.Looped == false then
				load_anim.Looped = true
			end
			
				debris:AddItem(animation, 1.5)
				
				load_anim:Play()
				
				print("Done")
			end
	end
end

for i=0,#animation_fortests, 1 do
	load_anims(i)
	task.wait(0.2)
end

--ignore that down here.

--local num = tonumber(string.match(folder.dummyblade_slash1.Name, "%d+"))
--print(folder.dummyblade_slash1, num)

Thanks for any help you provide to me!

  1. Loading animations through Humanoid is deprecated, use Animator instead (a child of Humanoid). Load animations on Animator like you would with Humanoid.
  2. for loops have since improved, you no longer have to specify in pairs or in ipairs or anything, just do
for _, v in folder:GetChildren() do
        --whatever you wanna do
end
  1. Not sure why you would want to load and play the animation on the server, any AnimationTrack that was loaded on a Player’s Animator through a server-replicated Animation instance (it has to be created on the server) and played on the client will replicate to the server and other players

My overall suggestion is to make it modular (and required on the client), it will be much easier for you to specify things instead of doing it in the script itself. If you want to go even deeper (and this is probably “overengineered” and redundant), use Object Oriented Programming to handle animation instances and play them.

thanks!
i appreciate the support