What is better to use?

A

local TweenService = game:GetService("TweenService")

local Up = TweenService:Create(script.Parnet, TweenInfo.new(), {
   Position = Udim2.fromOffset()
})

local Down = TweenService:Create(script.Parnet, TweenInfo.new(), {
   Position = Udim2.fromOffset()
})

while task.wait(2) do
   Up:Play()

   task.wait(2)

   Down:Play()
end

B

local TweenService = game:GetService("TweenService")

while task.wait(2) do
   TweenService:Create(script.Parnet, TweenInfo.new(), {
      Position = Udim2.fromOffset()
   }):Play()

   task.wait(2)

   TweenService:Create(script.Parnet, TweenInfo.new(), {
      Position = Udim2.fromOffset()
   }):Play()
end

Is there a difference here? if there is, which will work better in terms of performance?

You’d rather create one and then reuse it over and over again. Creating multiple ones isn’t exactly great, and it becomes harder to fix if the code somehow grew later.

1 Like

Definitely A; creating tweens is expensive because it has to calculate the points.

1 Like

Option C!

local TweenService = game:GetService("TweenService")

local Up = TweenService:Create(script.Parent, TweenInfo.new(), {
   Position = Udim2.fromOffset()
})

local Down = TweenService:Create(script.Parent, TweenInfo.new(), {
   Position = Udim2.fromOffset()
})

Up:Play()

Up.Completed:Connect(function() 
    task.wait(2)
	Down:Play()
end)

Down.Completed:Connect(function()
    task.wait(2)
	Up:Play()
end)
2 Likes