How can i get multiple tweens to play at the same time using my existing code?

Im trying to get these tweens to play at the same time but right now they are playing separately from the for loop that calls the OpenPage function. How can i get them to play at the same time?

local function tweenLeft(ui)
	local y = ui.Position.Y.Scale
	local x = ui.Position.X.Scale
	ActiveTweens[ui.Name] = x
	local ti = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
	TweenService:Create(ui, ti, {
		Position = UDim2.new(1, 0, y, 0)
	}):Play()

end

local function tweenRevert(ui)
	local y = ui.Position.Y.Scale
	local prevPos = ActiveTweens[ui.Name]
	local ti = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
	TweenService:Create(ui, ti, {
		Position = UDim2.new(prevPos, 0, y, 0)
	}):Play()
end


local function OpenPage(frameToOpen)
	for i,v in pairs(script.Parent.BackgroundFrame.MenuFrame:GetChildren()) do
		if v:IsA("ImageButton") or v.Name == "Patch" or v.Name == "Updates" then
			tweenLeft(v)	
		end
	end
end

local function ClosePage(frameToClose)
	for i,v in pairs(script.Parent.BackgroundFrame.MenuFrame:GetChildren()) do
		if v:IsA("ImageButton") then
			tweenRevert(v)

		end
	end
end

Which for loop are you referring too? Sorry If I don’t understand the question

The OpenPage function runs by a for loop that i forgot to link into the post.

for i,v in pairs(MenuFrame:GetChildren()) do
		if v:IsA("ImageButton") then
			local mDebounce = false
			v.MouseEnter:Connect(function()
				if mDebounce == false then
					mDebounce = true
					hover:Play()
					wait(0.1)
					mDebounce = false
				end
			end)
			local dBounce = false
			v.MouseButton1Click:Connect(function()
				if dBounce == false then
					dBounce = true
					OpenPage()
					wait(2)
					ClosePage()
					dBounce = false
				end

			end)
		end
	end

Can you take a video(or explain in detail) of what currently happens and what you want to happen

Hey,
I think you can use task.spawn at every loop so it can run when the script is running

try using spawn or task.spawn functions to run the tweens in a separate thread

3 Likes