Pause localscript execution until TweenPosition completes?

Hi!
I’d like to have a loop, for an information screen, using a screengui.
It’d be useful if the script paused automatically before continueing with the next tween. I think believe to remember that it was like that in the past, but I’m not sure.

GUI:TweenPosition(Udim2.new(1,0,1,0),"Out","Quad",5)
print("Done with first!")
GUI:TweenPosition(Udim2.new(0,0,,0),"Out","Quad",5)

Thanks in advance! :slight_smile:

1 Like

wait(5)

Maybe this is what you’re looking for?

Lol,I know I can use that, but I remember that like a month ago, I managed to just use 1 line of code.
Thanks for trying, though!

This would it be if it’s like what I mean:

GUI:TweenPosition(Udim2.new(1,0,1,0),"Out","Quad",5)
GUI:TweenPosition(Udim2.new(0,0,,0),"Out","Quad",5)

Alright. I don’t recall TweenPosition ever being able to yield, but maybe I’m wrong.

Edit: I am probably very wrong but :Wait() ?

Alright, is there a thing like:

GUI:TweenPosition(Udim2.new(1,0,1,0),"Out","Quad",5):Wait()

The best way to do it is as @Voidage stated.

If you really don’t want to do that, I suggest you look into TweenService. The Tween object has a “Completed” event.

I don’t think so. Maybe you could look for your old code and see if you can find what you did? I still think a wait is the only way. I’ve never seen anyone else do it another way.

Alright, thanks!

Alrighty! It’s still early in the morning for me, so I’m most likely still sleeping, lol.

Thanks for the help! :slight_smile:

1 Like

The 6th argument of TweenPosition is a function that runs when the tween is completed. You shouldn’t use it though as it is bad practice.

Gui:TweenPosition(Position,“Out”,“Quad”’,1,true,function() print’tween over’ end)

Thanks!

The Tween members on UI objects shouldn’t be used because they have strange limitations and TweenService can do everything that these methods can and more. The tween methods on UI will probably be deprecated at some point. Use TweenService instead. You can wait for the tween to complete like so:

local tween = TweenService:Create(Gui, TweenInfo.new(...), {Position = ...})

-- OPTION 1:
tween:Play()
local state = tween.Completed:Wait()
-- do action after tween

-- OPTION 2:
tween.Completed:Connect(function(state)
    -- do action after tween
end)
tween:Play()
14 Likes