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.
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.
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.
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.
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.