Adding delay to animation script

hello guys, i have a script that plays anims on meshes and it works but i want it to play after delays but the script just plays continiously without a stop regardless of adding wait, is their any fixes?

local char = script.Parent
local animController = char:FindFirstChild("Humanoid") or char:FindFirstChildOfClass("AnimationController")


local animation1 = script.Charge
local animation2 = script.GoingShoot
local animation3 = script.Shoot


local animTrack1 = animController:LoadAnimation(animation1)
local animTrack2 = animController:LoadAnimation(animation2)
local animTrack3 = animController:LoadAnimation(animation3)


animTrack1:Play(0,1,1)
animTrack2:Play(0,1,1)
animTrack3:Play(0,1,1)

Can you elaborate more on the delay you want to add?
Does the delay vary? Is it something related to user inputs? What is your goal with adding the delays?

so basically the animation plays all the time i want it to stop for a bit and then play each time and it has nothing to do with user inputs

Just use task.wait(time) to alternate between pause() and resume() or whatever it’s called.

i tried using wait() on between each last 4 lines and it did not work

Hey there,

if the animation is “playing endlessly”, ensure that when you export your animation Looped is set to disabled, otherwise set that property to false per animation.

As far as delays go, you could try the task.delay function to see if it’s closer to a resolution you’re looking for.

2 Likes

oh after i set the looped to disabled how do i make it so it stops every 10 seconds and then plays

I’m confused, but I’ll try to understand anyways.


If you want an endless loop, you can make use of a while do loop.

while true do
   --animation1
   --task.wait(<any delay you want in between the animations>)
   --other animations
task.wait(10) --the by you mentioned wait time between loops
end

This should in theory run forever. If you want to be able to pause the loop (optimization sake), you can make a local variable and use a repeat until to make it break the loop.

Example of the repeat loop
local loopAnimation = true

repeat
   --animations with or without delays inbetween
until loopAnimation == false
1 Like