Question, How Do I Loop Something?

As the Title says, How do i loop Something. I’m trying to Make it so the Title would move up and down. Here is a example code:

local Title = script.Parent.Parent
--What do i put here?
Title:TweenPosition(UDim2.fromScale(0.173,0),Enum.EasingDirection.In,Enum.EasingStyle.Sine, 0.4)
wait(0.4)
Title:TweenPosition(UDim2.fromScale(0.173,-0.1),Enum.EasingDirection.In,Enum.EasingStyle.Sine, 0.4)
--Do I put End here?

Thank you, and answers help…

local Title = script.Parent.Parent
while true do -- need to be true in order to loop
    Title:TweenPosition(UDim2.fromScale(0.173,0),Enum.EasingDirection.In,Enum.EasingStyle.Sine, 0.4)
    wait(0.4)
    Title:TweenPosition(UDim2.fromScale(0.173,-0.1),Enum.EasingDirection.In,Enum.EasingStyle.Sine, 0.4)
    wait(0.4)
end
2 Likes

You can put it in a while true do loop. You also have to add a wait after your second tween.

New code:

--//Variables
local Title = script.Parent.Parent

--//Loops
while task.wait(0.4) do
	Title:TweenPosition(UDim2.fromScale(0.173, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.4)
	
	task.wait(0.4)
	Title:TweenPosition(UDim2.fromScale(0.173, -0.1), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.4)
end

Same as the other 2 above me said, although you can replace the task.wait(0.4) to wait(0.1) for a smoother and faster GUI floating effect.

This won’t work, and will just reset the current tween playing because :TweenPosition doesn’t yield until the tween is finished.

Also, you should use task.wait(n) over wait(n), because it’s more performant and accurate.

oh right. common mistake on my end. thanks for correcting! also why would they have both wait and task.wait then? wouldn’t everyone be using task.wait if they knew that?

Everyone should be using task.wait(n), it’s just that since it’s a fairly new global, not many people know about it.