Tween doesn't play when played already

  1. What do you want to achieve?
    I want to make something that rises continuously using only one tween.

  2. What is the issue?
    Whenever I play the same Tween again, it doesn’t work.

  3. What solutions have you tried so far?
    I tried making individual tweens, changing positions, repeating tweens, but they don’t work.

Original Script: (Showing only necessary code)

--[[ Variables ]]--

local TweenService = game:GetService("TweenService")
local Water = workspace.Water

--// TweeningInfos

local TweeningInfo3 = TweenInfo.new(
	
	0.4,
	Enum.EasingStyle.Quart,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

--// PartInfos

local PartInfo3 = {
	
	Position = Water._Water1.Position + Vector3.new(0, 5, 0)
}


--// Tweens
local Tween3 = TweenService:Create(Water._Water1, TweeningInfo3, PartInfo3)

wait(7.58) -- 14.2
Tween3:Play()

wait(0.4)
Tween3:Play()

wait(0.4)
Tween4:Play()

wait(0.4)
Tween5:Play()

wait(0.5)
Tween6:Play()

wait(0.4)
Tween7:Play()

wait(0.4)
Tween8:Play()

wait(0.4)
Tween9:Play()

wait(0.5)
Tween10:Play()

wait(0.4)
Tween11:Play()

wait(0.4)
Tween12:Play()

wait(0.4)
Tween13:Play()

wait(0.5)
Tween14:Play()

wait(0.4)
Tween15:Play()

wait(0.4)
Tween16:Play()

wait(0.4)
Tween17:Play()

Thanks for reading!

help please
im making this for a map

i actually found multiple mistakes here, but dont worry.

first, you only made Tween3. Calling Tween11 or Tween4 when they dont exist will error your code.
second, you only defined position once, so calling tween3 continuously would just teleport your water to that originally defined position

heres an explanation on how I would code this (takes like 5min to code)

  1. find your object
  2. run a while-loop on it that waits the tween duration
  3. run a new position tween inside the loop that is x higher from waters old height

heres a code snippet, you can see it follows the steps

local waterObject = game.Workspace:WaitForChild("Water") -- ensure we load the water
local tweenTime = 0.5 -- we use this in many places, so its easier to edit all those times here
local tweenInfo = TweenInfo.new(
    tweenTime, 
    Enum.EasingStyle.Quart, 
    Enum.EasingDirection.Out
)

while wait(tweenTime) do
    local tweenGoal = {Position = waterObject.Position + Vector3.new(0,5,0)}
    local myTween = game:GetService("TweenService"):Create(waterObject, tweenInfo, tweenGoal)
    myTween:Play()
end

You put 0 for Repeat Count, which means that it will play only 1 time so that it plays endlessly, you can put any number less than 0.

local TweeningInfo3 = TweenInfo.new(
	
	0.4,
	Enum.EasingStyle.Quart,
	Enum.EasingDirection.Out,
	-1,
	false,
	0
)

And as @Onebeets said, you can use while wait() do.

local rand = math.random(3,7)
local Tween3 = TweenService:Create(Water._Water1, TweeningInfo3, PartInfo3)

while wait(rand) do
      Tween3:Play()
end
1 Like

additionally i forgot to say, while loop can be put into coroutine or spawn so it wont stop the rest of script if stuff is added after the while loop, like so

spawn(function()

    -- while loop goes here
end)
coroutine.wrap(function() -- better for long-term learning than spawn

    -- while loop goes here

end)() -- parentheses run the wrap function so we dont need to define it
1 Like

Thanks, I forgot to mention this.

Oops! I forgot about the nonexistent tweens. In the real code, they’re all gonna play Tween3, which doesn’t work.

Also, thanks for your response! The output I want is gonna have an interval, which goes with 0.4, 0.4, 0.4, 0.3 wait functions, while it continuously rises.

Don’t understand properly? Basically, it’s an inspiration from the Flood Escape 2 Community Map “Technological Destruction”.

Here’s a video reference on what I expect for the output to be, start at 0:50 to see what I mean.

Thanks a lot!

It’s fixed now. Thank you!

Applying the knowledge from Onebeets’s code, I made this:

while true do

	local tweenGoal = {Position = Water._Water1.Position + Vector3.new(0,5,0)}
	local myTween = TweenService:Create(Water._Water1, TweeningInfo3, tweenGoal)

	myTween:Play()
	Interval = Interval + 1
	
	if Interval ~= 4 then
		
		wait(0.4)
		print("Interval " ..Interval)
		
	elseif Interval == 4 then
		
		wait(0.5)
		Interval = 0
		print("Interval RESET")
	end
end

And in the future, I will be using the coroutine function soon. Thanks for helping!