Quirk: Animation plays only if following task.wait() call

Hi there,

I plan to make a new revolutionary Roblox experience (will be called “Guess Yourself”).
It will require me to get familiar with the Roblox animations.

I slightly modified first example from the official animation docs: changed the ID to the animation I made, removed the bit with animation events and (eventually) added task.wait() call:
(LocalScript placed inside StarterPlayerScripts)

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")

local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = "rbxassetid://118986049327664"

local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
kickAnimationTrack.Looped = true

task.wait() -- remove this and it will not work. Note - no wait time being passed

kickAnimationTrack:Play()

Without task.wait() the animation will not play. I get no errors about it, everything seems to be loaded and ready to go.

Why does this happen? I assume it could be one of the following:
a) this is not how aminations should be used (start blasting some animation right when a character loads in)
b) there is some timing quirk that I should be aware of

Thank you for your insights.

See if this one works.

local Players = game:GetService(“Players”)

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local humanoid = character:WaitForChild(“Humanoid”)
local animator = humanoid:FindFirstChildOfClass(“Animator”)

local KickAnimation = Instance.new(“Animation”)
KickAnimation.AnimationId = “rbxassetid://118986049327664”

local KickAnim = animator:LoadAnimation(KickAnimation)
–Instead of making it loop manually you should edit the animation itself!

–Without task.wait()

KickAnim:Play()

Hi, i tested this code with improvement. For some reason animation is playing, but doesn’t show in game. I think animation can be played only after some time passed. By the way, if you code task.wait() without number, script also wait some time, as i know ~0,016 sec. Sorry for bad English
image

image

Hmm.

Check if the animation id you copied is owned by you and it is the correct id.

Check if the player’s character is set to the body type the animation used. (R6 or R15)

I replaced animation ID in code to my animation ID because i cant load animation that don’t own

Also animation playing if left task.wait()

The reason of this is cause animations dont instantly load, if you play the animation without the task.wait, at that point the animation wouldnt have loaded.

From the look of it I wouldn’t worry about it, as it shouldn’t matter to much.
In the case that you need an animation to play at an exact time, I would recommend loading an animation the second the players character loads in.

But again in this case, there isnt a reason to worry about it, as its only a 0.03 second difference.

If I recall correctly the minimum a task.wait can well, wait is 0.03, so unless roblox updated it not to long ago, I believe task.wait() when blank, or waiting 0 seconds, will actually wiat 0.03 seconds.

Hi! task.wait() is more performance and precise vervion of wait()

wait() updates once at ~0,032 second
task.wait() updates once at ~0,016

you can check it with this code:

while task.wait() do --You can change this to wait()
	print("Update")
end

There will be more updates per second when task.wait() used

Again, sorry for bad English

Huh, I thought task.wait() was still stuck at 0.03. Well thanks for the info!

You dont need to apologize! Its totally fine!

I will assume this was the case. Added a while loop to wait until animation track property Length is not zero, and the animation played. Thought it would error out or would wait to load if I tried to play it before it is fully loaded :person_shrugging:

1 Like

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