How do I make my tween loop?

  1. What do you want to achieve?
    I would like to make it so that my tween loops, until the TEXTBUTTON is pressed, and then the tween stops.

  2. What is the issue?
    I cannot figure it out, and no post has helped me so far on the developer forum.

  3. What solutions have you tried so far?
    I have had a look around the developer forum, however I have not found a post that has helped me.

cutscene2

cutscene3

You can loop a tween by setting the tweeninfo to -1

local Info = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut,-1, false, 0)

1 Like

The -1 does not work, I have tried before.


Seems to work for me, unless your using a different method.

You could use a repeat until loop, learn more here: Loops :+1:

Just need to do

repeat
Tween:Play()
Tween.Completed:wait()
Tween:Play()
until --until what ?

Something like this no ?

My script is for UI, not for parts guys.

Seems to be working fine for me, or you could use until loops as suggested.


code:

local frame = script.Parent
local TweenService = game:GetService("TweenService")
local framepos = frame.Position
local tweenInfo = TweenInfo.new(
	1, -- Time
	Enum.EasingStyle.Quad, -- EasingStyle
	Enum.EasingDirection.InOut, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)
local tween = TweenService:Create(frame, tweenInfo, {Position = framepos + UDim2.new(0,0,0.05,0)})
tween:Play()
function onclick()
	tween:Cancel()
	--code here
end

script.Parent.MouseButton1Click:connect(onclick)