Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to loop an animation correctly?

Code I have so far:

while wait(8.07) do
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://5152681449"
local control = script.Parent.Humanoid
control:LoadAnimation(animation):Play()
end

How do I loop an animation so it loops when the animation ends? The current loop I have makes it restart midway through the animation.

1 comment

0

Animations have a loop property. Tick it. No need to do this manually.

1 answer

The animation track object has a property named Length. You can use this to do a while loop every time the animation is done.

while true do
	local animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://5152681449"
	local hum = script.Parent.Humanoid
	local animTrack = hum:LoadAnimation(animation)
	animTrack:Play()
	wait(animTrack.Length)
end

I hope this helps :)

3 comments

0

do I set length as a variable or what?

0

because i'm getting the error that 'length' is not a valid member of animation :((

0

Oh sorry my bad let me edit that and check the code again :)

This discussion is preserved as it was. New answers, comments, and votes are closed.