My 2nd tween doesn't work

So right now I’m looping through a table of parts in my workspace, I want to similtaenously do a tween where it goes up and another that goes down, Like a hovering effect.

Right now the problem is it only animates the first tween, if I use tween.Completed, it yields my for i,v pairs loop and it doesn’t make the parts animate at the same time.

I have tried to put the tweening into diffrent functions and calling them from the i,v loop but still same problem

--Services-- 
local tweenService = game:GetService("TweenService")



--Tables-- 

local function getParts()
	local allParts = {}
	local folder = game.Workspace:WaitForChild("Folder")
	for i,v in pairs(folder:GetChildren()) do 
		table.insert(allParts, v)
	end
	return allParts
end 

print(getParts()[1].Name)

--Vairables-- 
local part = getParts()
local Time = 5
local tweenInfo = TweenInfo.new(Time, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1 )



local function up(part)
	local newPos = CFrame.new(0, 1, 0)
	local tween = tweenService:Create(part, tweenInfo, {CFrame = part.CFrame * newPos})
	tween:Play()
end

local function down(part)
	local endPos = CFrame.new(0, -1, 0)
	local tween2 = tweenService:Create(part, tweenInfo, {CFrame = part.CFrame * endPos})
	tween2:Play()
	
end

local function animations(part, Time, Dist, bool)
	--Variables-- 
	--local tweenInfo = TweenInfo.new(Time, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1 )
	
	
	for i,v in pairs(part) do 
		down(v)
		up(v)
		
		--local newPos = CFrame.new(0, 1, 0)
		--local endPos = CFrame.new(0, -1, 0)
		
		
		
		--local tween = tweenService:Create(v, tweenInfo, {CFrame = v.CFrame * endPos})
		--local tween2 = tweenService:Create(v, tweenInfo, {CFrame = v.CFrame * newPos})
		--tween:Play()
		--tween2:Play()
		
	end
	
	
	
	
end


animations(part, Time)

TweenInfo has a boolean reverse property, you could possibly use that instead.

If not, you’ll need to make it synchronous by Waiting on Completed but have the repeat loop as 0 since this’ll let it continue, overriding the down Tween. Furthermore, a Coroutined while loop will be needed in order to make it repeat.

1 Like

I’m not sure how to use the reverse property, I get a error saying that reverses can’t be assigned to

local tweenInfo = TweenInfo.new(Time, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 2)
tweenInfo.Reverses = true 

local info = TweenInfo.new(Time, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0 true)
print("tweened")

You need to pass it as an argument right there rather than change it separately, kind of like changing a Udim2’s X.Scale in the constructor function rather than overwriting the current scale separately.

1 Like

thanks everyone It works now :slight_smile: :slight_smile: :slight_smile: