Animations Delaying

There seems to be some delay before the animations (startAnim, chargeAnim, and endAnim) play, and I need it to play almost immediately or else another script won’t work properly. It seems to happen less on chargeAnim and startAnim. While it’s delaying, the animation tries to go back to the default animation. The delay sometimes happens and sometimes doesn’t, there’s a video with the delay happening below:

local script in the tool the player is holding:

local tool = script.Parent
game.Players.LocalPlayer.CharacterAdded:wait()
local char = game.Players.LocalPlayer.Character
local human = char.Humanoid
local anims = char.Animations

local startAnim = human:LoadAnimation(anims.axeBegin)
local chargeAnim = human:LoadAnimation(anims.axeCharge)
local endAnim = human:LoadAnimation(anims.axeFinish)

local playing = false
local activated = false

local function restoreChar()
	startAnim:Stop()
	chargeAnim:Stop()
	endAnim:Stop()
end

tool.Activated:Connect(function()
	if playing == false then
		playing = true
		activated = true
		startAnim:Play()
		startAnim.Stopped:wait()
		chargeAnim:Play()
		local charge = 0
		while wait(0.05) do
			charge = charge+0.05
			--if charge = multiple of 4
			if math.floor(charge/4)*4 == charge then
				chargeAnim:Play()
			end
			if activated == false then
				if charge < 1 then
					restoreChar()
					playing = false
				else
					chargeAnim:Stop()
					endAnim:Play()
					endAnim.Stopped:wait()
					restoreChar()
					playing = false
					break
				end
			end
		end
	end
end)

tool.Deactivated:Connect(function()
	activated = false
end)

Maybe it’s because the wait times are inaccurate. Try using AnimationTrack.Stopped:Wait() so it just yields for however long the animation plays instead of the wait()s

I timed it correctly, and I actually tried doing that while I was waiting for a reply, but it didn’t fix it completely. endAnim seems to be waiting for even longer but the other parts seem to be doing better.

EDIT: I updated the post to show the new script after I edited it a few times.

I think the problem here is that while wait() loop is causing it to go reeee. In other words try preloading the assets instead of busy cycling

How do you preload the assets?

I support the both ideas that Devs told you. I would like to add that maybe using events inside the animations could work, instead of using waits()

Place a marker inside the animation, on a keyframe, and use it to trigger the next animation and do the things u need to do in the middle. Using events to trigger functions is more reliable than trust on the waiting time. Use GetMarkerReachedSignal

Messed around with the script a bit (made things work better) and it fixed the bug in the process so it’s fine now.

If you are looking for answer about aniamtions delaying here, please look here: (This will explain how or why but not fully although it has good solutions for solving your delayed animations)