Pausing a tween in a loop

I cant manage to figure out how to add a pause in between the tweens. The script below is a moving model script using PrimaryParts CFrame. How would I be able to add a pause and keep performing this pause in a loop.

wait(2)
local TweenService = game:GetService("TweenService")
local model = workspace.Model
local root = model.PrimaryPart
local defaultTweenInfo = TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,-1,true,0)


TweenService:Create(root, defaultTweenInfo, {CFrame = workspace.Part1.CFrame}):Play()



TweenService:Create(root, defaultTweenInfo, {CFrame = workspace.Part2.CFrame}):Play()
3 Likes

Make a “cooldown”, I believe that part of your script is inside a while of for loop. If that’s the case, do this.

while cooldown = false do
     cooldown= true
     wait(2)
     --Type here the rest of your code

     cooldown = false
end

So what this does is whenever it goes inside the loop, it will have a cooldown in which it can not be able to enter the script again until the cooldown is off.

I tried it your way but it still doesn’t pause.

I’m clueless on how to fix this problem.

Unsure if this is what you’re looking for by “pause in between the tweens” but:


wait(2)
local TweenService = game:GetService("TweenService")
local model = workspace.Model
local root = model.PrimaryPart
local defaultTweenInfo = TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,-1,true,0)


local Tween1 = TweenService:Create(root, defaultTweenInfo, {CFrame = workspace.Part1.CFrame}):Play()

Tween1.Completed:Wait() -- wait for tween to finish

wait() -- whatever pause here

local Tween2 = TweenService:Create(root, defaultTweenInfo, {CFrame = workspace.Part2.CFrame}):Play()

Tween2.Completed:Wait()

I’m getting this error message.

[Workspace.Model.Script:10: attempt to index nil with ‘Completed’]

Try this instead


wait(2)
local TweenService = game:GetService("TweenService")
local model = workspace.Model
local root = model.PrimaryPart
local defaultTweenInfo = TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,-1,true,0)


local Tween1 = TweenService:Create(root, defaultTweenInfo, {CFrame = workspace.Part1.CFrame})
Tween1:Play()
Tween1.Completed:Wait() -- wait for tween to finish

wait() -- whatever pause here

local Tween2 = TweenService:Create(root, defaultTweenInfo, {CFrame = workspace.Part2.CFrame})
Tween2:Play()
Tween2.Completed:Wait()

Do you mean you want to pause the tween whenever a certain condition meet in a loop?