How would I make my GUI Tweening smooth?

Hello, I’m Techyfied. I’m currently working on UIs. But I have a problem with my UI. It’s not tweening correctly. It lags a bit, and its slow. I’d love if you help me fix this script.

Problem

Here is my GUI -

Script

local Button = script.Parent
local Frame = script.Parent.Parent.Box

function onClick()
	Frame:TweenPosition(UDim2.new(0.112, 0, 0.115, 0))
	Button.Visible = false
end

Button.MouseButton1Click:connect(onClick)

--[[
Frame main pos: {0.112, 0},{0.115, 0}
Frame hid pos: {1.112, 0},{0.115, 0}
]]

Note: It’s sometime laggy, and sometimes smooth. But it’s mostly laggy.

Thank you for reading :slight_smile:

2 Likes

I tested your script and it seems to work fine on a default frame. Maybe the problem is just inside your frame.

Maybe that’s the problem. My frame contains a lots of buttons & scripts. Is there any way to fix it?

(Forget I asked this) Are you using the script for multiple buttons of the same Gui Object? (excluding the ScreenGui)

Code tips: Localize your function and use Connect instead of the deprecated connect.

I’m using just for the frame. All the buttons are inside the frame, and I’m moving the frame only.

Yeah I see nothing wrong with the script, are you positive that others are experiencing it as well if they tried out the place?

Yep, i have another gui in the game (bottop left in the video), i used the same script for that, and its laggy too.

I mean for other people, not other GUIs.

Are you running this from a server script or local script? Tweening a GUI’s position from a server script can be laggy because the server is already loaded with other tasks depending on the size of your game.

If you’re running this from a local script, my only explanation is that your PC’s framerate isn’t doing very well due to performance and what not. If you’re running a solid 60fps and the tween still lags on a local script, then I don’t really know what’s going on either.

1 Like

I am using server script. (30 char)

Try copy and pasting the entire code into a local script instead. Like I said, the server isn’t the best place to handle such tweens since it’s already handling other important things necessary for the game to run. Your own client would be a much better place for the movement to render since it’s handling fewer things than the server is.

Why exactlly are you tweening it on the server script? I’d use RemoteEvents instead then so you can tween it on client side and also the thing tweening is taking a lot more performance on server script instead of client side.

Take a look at documentary GuiObject | Documentation - Roblox Creator Hub

These are all the arguments you can pass with tweenposition.

To make it smooth adjust the speed to how you want it and I recommend the style to be quad.

1 Like

It is Bad practice to manipulate Guis on a ServerScript, all Guis should be changed from a LocalScript.

If you change the Gui from a ServerScript it will take time for the changes to replicate to the Client. Thus causing lag and unecessary Network Traffic.

change it to a localscript then try it

Okay, I will test it tomorrow, once I get on my pc and let you know the result. Thanks.

The only way you could ever have lag this bad is if you’re moving it from a server script instead of a LocalScript which I have no clue why that’d be the case. Never change Guis from a server script. Guis are client-sided, so you should be using LocalScripts to handle Guis.

The client will always move things much more smoothly than the server can. Practice doesn’t just apply to moving interfaces, applies to everything else as well.

Well, I’m new to scripting and I sometimes do some dumb things.

Thanks, I turned all of the scripts int LocalScript and it worked fine. I was too dumb to use those as server scripts lol