Animation Loading Issue

I’ve encountered a problem when playing animation from my script. The first time I use an animation, the character the animation is loaded on goes into a sort of t-posed pose before performing the animation, but after I load the animation once it works. I’ve tried preloading the animation ids, but that doesn’t work.

		local hitanim = Instance.new("Animation")
		hitanim.AnimationId = hitanimid

		local hittrack = standcontroller.Animator:LoadAnimation(hitanim)
		hittrack.Looped = false
		
		hittrack:Play()

that is a quick example of how I go about playing animations in my script. an example of where hit anim id is from can be from code block:

hitanimid = Animations[STAND.Value].rightpunch

(Of course, Animations is a module script that is required at the start of my script).
I was thinking of putting all animations in a folder instead of creating the animations everytime I want to use them, but that would take quite a lot of work considering my 28 different animations and many different usages of them. If you need any information regarding my script structure and more, I’d be happy to share.

Instead of loading the animation inside the attack function, load all tracks once when the script starts up. Store them in a table to play them instantly later.

-- Do this once at the top of your script
local loadedAnimations = {}
local animator = standcontroller.Animator

-- Loop through your module script data to load everything beforehand
for name, id in pairs(Animations[STAND.Value]) do
    local animInstance = Instance.new("Animation")
    animInstance.AnimationId = id
    
    -- Load it to the animator once and save it
    loadedAnimations[name] = animator:LoadAnimation(animInstance)
end

-- Inside your attack function, just do this:
local hittrack = loadedAnimations["rightpunch"]
if hittrack then
    hittrack:Play()
end
1 Like

Although this is a great idea, I don’t think it would work with my system. My system works by having changing “STAND” values. So when the stand value changes, the loading script you just gave would have to be played again and if I somehow got this to work it’d be quite messy. But I think that maybe my logic is wrong here:

local ContentProvider = game:GetService("ContentProvider")
local Animations = require(game.ServerStorage.standmodules.animations)

local preloadList = {}

for _, standAnims in pairs(Animations) do
	for _, animId in pairs(standAnims) do
		if typeof(animId) == "string" then
			table.insert(preloadList, animId)
		end
	end
end

print("Preloading " .. #preloadList .. " animations...")
ContentProvider:PreloadAsync(preloadList)
print("Finished preloading animations!")

which pretty much does your idea but makes it global. I’m not sure.

2 Likes

How this script fixes the issue

  • First Use: It creates the animation, saves it to the animationCache table, and plays it.
  • Every Use After: It bypasses the loading step completely and plays the saved track from the table instantly, which removes the T-pose delay.
  • No Extra Work: It reads your existing module script directly, so you do not need to create 28 folders manually.
-- 1. PUT THIS AT THE VERY TOP OF YOUR SCRIPT
local animationCache = {}


-- 2. USE THIS LOGIC INSIDE YOUR ATTACK FUNCTION
local standName = STAND.Value
local animId = Animations[standName].rightpunch

-- Check if this specific animation track was already loaded before
if not animationCache[animId] then
    local hitanim = Instance.new("Animation")
    hitanim.AnimationId = animId
    
    -- Load it to the character animator once and save it in the cache
    animationCache[animId] = standcontroller.Animator:LoadAnimation(hitanim)
end

-- Grab the saved track from the cache and play it instantly
local hittrack = animationCache[animId]
hittrack.Looped = false
hittrack:Play()

What I usually have done is put all animations in ReplicatedFirst and used PreloadAsync() on every Animation instance in the Folder. ReplicatedFirst gives priority to instances put inside it to be loaded first, using PreloadAsync puts the Animation in memory, which means the engine wont load the Animation into memory right when you’re trying to play it. Load those Animation Instances into the Animator instead of creating a new Animation Instance.

I know you said you already tried Preloading, but is it done the way i described above?

The problem is I don’t have a folder of the animation instances. Instead, I have a module script that has all the ids I then require it and create the animation instance right before loading it. Does preloading animations work by loading the instance or the id itself?

Try preloading the instance instead of an ID, just grab an ID from your script and put it in the AnimationId value, and see if that one animation is fixed before trying to apply it to all of them

IT APPEARS AS IF THE PROBLEM I AM FACING IS FROM NOTHING BUT A MERE STUDIO BUG, I APOLOGISE FOR WASTING YOUR TIME ( animations load perfectly fine when I test the game on actual roblox)