Should i improve anything about my animation preloader?

local replicatedStorage = game:GetService("ReplicatedStorage")
local contentProvider = game:GetService("ContentProvider")

local animationsFolder = replicatedStorage.Animations

function Init(player: Player)
	for _, animation in pairs(animationsFolder:GetChildren()) do
		local success, response = pcall(function()
			contentProvider:PreloadAsync(animation)
		end)
		
		if success then
			return
		else
			local character = player.Character or player.CharacterAdded:Wait()
			local humanoid: Humanoid = player:WaitForChild("Humanoid")
			local animator: Animator = humanoid:WaitForChild("Animator")
			
			animator:LoadAnimation(animation)
		end
	end
end

return Init()

Why would you post this twice? Try deleting one.

Sorry i thought i deleted the last one and i made a new one because i put the wrong category and didnt send the code as code in the last one

1 Like
  1. Why are you returning when success? This would mean you can only successfully load one animation.
  2. I think you meant to type character:WaitForChild("Humanoid") instead of player:WaitForChild("Humanoid").
  3. Why are you returning Init() which is nil?

Have you ran the script to see if it works?