How to make tween run infinitely

Hello! So I have this water texture animation, but I want it to run forever. However, if I use -1, it’ll reset back to its original pos. Please help!

local ts = game:GetService("TweenService")
local info = TweenInfo.new(8, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1)
local cs = game:GetService("CollectionService")
local rs = game:GetService("RunService")

for i, water in pairs(cs:GetTagged("Water")) do
	local texture = water.Layer3.TextureTop
	ts:Create(texture, info, {OffsetStudsV = 6}):Play()
	
end
2 Likes

Maybe use math.huge or 9999999999999999999999

Do you think your players are gonna stay that long? Even if your tween in 0.00000blahblahblah seconds it would still take a while

2 Likes

You could have a variable of the last texture position / change and run another tween when the previous tween is completed.

2 Likes

Then the water won’t move, only a miniscule amount

2 Likes

Wait 8 Seconds.
Tween it again the opposite way
Then put both in a while true loop

2 Likes

This might just be me being stupid, but would a while loop not work if you just wait for the tween to complete at the end?

2 Likes

if you use Tween.Completed, then no

1 Like

How come? Would enclosing the entire for each loop in a while loop not work, since you would just be creating the tweens again every time and you could just task.wait the tweens time property.

1 Like

It be fine.

Tween 8 Seconds to OffsetStudsV = 6
Wait 8
Tween again to OffsetStudsV = -6 or whatever
Wait 8

Put it in a while true loop.

1 Like

thinking about it now, the best way is to increase the offset by an amount every frame.

local texture = script.Parent:WaitForChild("Texture")

game["Run Service"].Heartbeat:Connect(function(delta)
	texture.OffsetStudsV += 5*delta
	--multiply by delta to keep it consistent over any framerate
end)
3 Likes

i think they want it to move constantly in the same direction, not move back.

1 Like

If it’s a repeating texture, you could just wait for the tween to complete and set the offset back to zero, but runservice would probably be better in the case of it moving in the same direction infinitely.

2 Likes

Oh I assumed by him saying

However, if I use -1, it’ll reset back to its original pos

I’m guessing now the texture isn’t made for infinite. i.e. has a visible line between end and start

1 Like

Yeah, sorry for making it confusing. This works!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.