How would I make an infinite tween?

  1. What do you want to achieve? Keep it simple and clear!
    Infinite animation / tweening
  2. What is the issue? Include screenshots / videos if possible!
    For the tween info under the repeat account how would I make an infinite repeat?
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried searching online but couldn’t find anything.
local tweenService = game:GetService("TweenService")
local Rock = script.Parent

local tweeningInfo = TweenInfo.new(
	
	3, -- Duration
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	-- Infinite repeat
	
	
	
	
)

Thank you!

3 Likes

math.huge is the simplest way to go.
It’s documented here on the Developer Hub, along with a bunch of other math stuff.

You could also do an infinite loop while true do (or something like it) and have it play every time the Completed event is hit if you wanted to.

8 Likes

I’ll try those solutions, thank you!

2 Likes

Tweens do actually have a built in way of making themselves run indefinitely. As per the wiki, it has the following snippet of:

local tweenInfo = TweenInfo.new(
    2, -- Time
    Enum.EasingStyle.Linear, -- EasingStyle
    Enum.EasingDirection.Out, -- EasingDirection
    -1, -- RepeatCount (when less than zero the tween will loop indefinitely) 
    true, -- Reverses (tween will reverse once reaching it's goal)
    0 -- DelayTime
)

The -1 for the RepeatCount parameter is what you are looking for. So in your case, that would give you this code:

local tweenService = game:GetService("TweenService")
local Rock = script.Parent

local tweeningInfo = TweenInfo.new(
	
	3, -- Duration
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	-1 -- Loop indefinitely

)

Best of luck!

32 Likes

That makes sense, I remember seeing something like that in js but didn’t know if it was used in Lua. Thank you!

1 Like

-1 is recommended rather than math.huge due to some possible issues? (i dont know them but they recommend -1 :man_shrugging:)

4 Likes

Well, I wouldn’t know of any issue with math.huge, but I’m no expert when it comes to programming languages (and nor will I pretend to be). math.huge on Roblox is basically something used to be larger than anything calculable by the system, so a pseudo-infinite in some way.

But I would think that using the -1 trick would be more likely to break later on. Someone in the future’s gotta see that and be like, “Wait, that makes no logical sense, ERROR.”

Whatever works, works though.

2 Likes