Animation takes about half a second to load after :Play() is called

Hi there, I am hoping that someone with more experience with animations can help me out with a problem I am having.

I am making an FPS framework and when I am trying to play the animation for equipping the tool, the animation will not play for about half a second. This is okay if the animation takes longer than that, but my equip animation is 0.4 seconds long meaning it looks like the tool just snaps into place.

When I set the animation’s playback speed to be 10x longer than it should (i.e. calling :Play(0,1,0.1), it works fine and looks good because the animation has time to load and play.

Below is my current client-side script that handles the first person animations. I begin by preloading the animations into a dictionary (loadedAnims). It is organized such that I can do loadedAnims[<<Insert tool name>>][<<Insert action name>>]:Play() and it will play the appropriate animation for the action

-- This script handles the local first person hand animations for the player

repeat wait() until game:IsLoaded()

-- Script constants -------------------------------------
local rs = game:GetService("ReplicatedStorage")
local fArms = rs.FakeArms
local handleWeld = fArms["Right Arm"].Handle
local animator = fArms.AnimationController.Animator
local cam = workspace.CurrentCamera
---------------------------------------------------------
-- Script variables -------------------------------------
local loadedAnims = {}
local currItem = ""

fArms.Parent = cam

-- LOAD ALL FIRST PERSON ANIMATIONS ---------------------------------------------
for i,v in pairs(rs.Animations.FirstPerson:GetChildren()) do
	loadedAnims[v.Name] = {}
	
	for z,x in pairs(v:GetChildren()) do
		if x:IsA("Animation") then
			local newAnim = animator:LoadAnimation(x)
			loadedAnims[v.Name][x.Name] = newAnim
		end
	end
end
---------------------------------------------------------------------------------

Then, when I want to equip an item, I call a separate function equipTool(toolName) that will play the “Equip” action animation, wait until it completes, then play the “Idle” action animation. If another tool was equipped before, it will also stop all of the previous tool’s animations

-- ANIMATES THE HANDS EQUIPPING A TOOL ------------------------------------------
local function equipTool(toolName : string)
	if currItem ~= "" then
		for i,v in pairs(loadedAnims[currItem]) do
			v:Stop()
		end
		fArms[currItem].Parent = rs.Items
	end
	
	currItem = toolName
	if toolName ~= "" then
		local toolModel = rs.Items[toolName]
		toolModel.Parent = fArms
		handleWeld.Part1 = toolModel.Handle
		
		loadedAnims[toolName]["Equip"]:Play(0)
		wait(loadedAnims[toolName]["Equip"].Length)
		loadedAnims[toolName]["Idle"]:Play(0)
	end
end
----------------------------------------------------------------------------------

Here is a video showing what I am talking about

External Media

Is this just a limitation of the engine, or is there a way to get around this?

I think I found out exactly why and it is laughably silly. I have a wait statement in the equip script, so the code to show the arms / move them to the camera doesn’t play until after the equip animation is done and thus I am unable to see it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.