Can i optimize this?

ive made this script which uses tween service to tween gui’s in my game, each function (event 1,2,3) were in a sperate local script so ive tried putting all together in one local script since on their own they were quite laggy, and this seems to reduce the lag but im wondering, is this how a pretty avrage tweenservice script should be? im pretty new to scripting and i want to know if this reaches its maximum potential or i can optimize this somehow

They’re all pretty much the same so you really only need 1 event. Then you can pass which gui you want to open. I would also add the variables outside of the function so you don’t repeatedly have to wait for it.


local Frames = {
   Example = frame,

   — guiName would be called “Example”
   if Frames[guiName] then
      local frame = Frames[guiName]

You should also use task.wait(). If you want you can resend the script after to make sure everything looks good.