Performance with TweenService?

I’ll be straight to the point, I want to create a function that takes different types of UDim2 Positions as it’s argument, makes a Tween out of that position and then plays the Tween immediately afterwards under certain conditions

Will there be a slight delay/lag if I do that?

local TweenService = game:GetService("TweenService")
local anyTextButton = game.Players.LocalPlayer.ScreenGui.TextButton -- Underneath StarterGui, ScreenGui

local info = TweenInfo(...) -- Omitted
local condition = false --If player Held the Mouse down

local function foo(Button, Position)
   local Tween = TweenService:Create(Button,info,{Position = UDim2.new(Position))
   if condition then
      Tween:Play()
   end
end

anyTextButton.MouseEnter:Connect(function()
   foo(anyTextButton, UDim2.new(1,2,3))
end

As you can see, when the player moves their mouse over the TextButton an event occurs where a Tween is created. Checks if the player held the mouse down, if so, then play the Tween.

But what happens if they instead move the mouse erratically over the TextButton? The Tween will be rapidly created then discarded. I feel like there might be a lag that might happen.

1 Like

Maybe try adding a Tween.Completed:Wait() after the Tween:Play()?

There’s no problem with the script in question. I can’t add the wait since I need it. And this question can only really be answered by people that know the coding inside TweenService functions.