Animation Loading Issue

I want get the length of the animation when it play / before it play and add it to wait down at the bottom.

The issue is I can’t seems to get the length of my animation when it play for the first time,
more specifically it return “0” then the second time it will get me the actual length, I want to get
the length the first time and use it.

I have tried to load the animation before the sword swing but then it looks wired if I am not attacking for the first time. I have also tried searching for a solution here but, can’t seems to find it or, might just type in the wrong problem. If anyone got ideas or a links to other post, I love to hear it.

local function LoadAnimation(playerHumanoid, tool, animationName)
	local animation = tool:FindFirstChild(animationName)
	local loadAnimation = playerHumanoid:LoadAnimation(animation)
	return loadAnimation
end

local function BasicAttack(playerHumanoid, tool, animationName)
	local loadAnimation = LoadAnimation(playerHumanoid, tool, animationName)
	loadAnimation:Play()
	
	local animationLength = loadAnimation.Length
	print(animationLength)
	wait(animationLength)
end

local function SwingingSword(player, tool, inputState)
	local playerCharacter = player.Character
	local playerHumanoid = playerCharacter:FindFirstChild("Humanoid")

	if inputState == Enum.UserInputState.Begin then
		local basicAttackAnimationName = "BasicAttack"
		BasicAttack(playerHumanoid, tool, basicAttackAnimationName)
	end
end

SwordSwingEvent.OnServerEvent:Connect(SwingingSword)

You could use .Stopped:wait()

loadAnimation.Stopped:wait()
1 Like

Sweet thanks it works, test it tick() and the time different is .04 second delay the first time and
.004 delay after it load. want to be precise as possible with these animation.