I believe this should be a pretty simple question. I have a localscript inside a GUI, and when the user activates the Exit button it does script.Parent:Destroy() to delete the GUI. I noticed, however, that this only deletes the GUI on the client. Is it the best practice to also delete the GUI on the server (By firing a RemoteEvent prior to local deletion) so the server doesn’t continually get clogged with GUIs that are no longer on the client?
If so, are there any recommendations on securely doing this? Possibly just doing something like the following?
DestroyObj.OnServerEvent:connect(function(plr, objName)
local obj = plr.PlayerGui:FindFirstChild(objName)
if obj then
if obj:isA("ScreenGui") then
obj:Destroy()
end
end
end)
If you seriously need to delete the UIs, then it’d be good practice to do it on the client (to reduce latency) and then server (to prevent a memory leak). Your example should work. But if you just need to make the UI invisible, do what @BigBoyer007 said. You can always make a frame’s Visible property false or just disable the Enabled property of a ScreenGUI.
The only need for Gui’s to be operated/interfered with on the server would probably just be for RemoteEvents/RemoteFunctions keeping the information stored on the server, sending information back to all of the clients, or a single client if you’re referencing a specific user.
Most of the time, all Gui based things are relying off whatever your screen contains; for example: If you want to close a gui, you don’t need the server to close something on your screen, all you would need is a client script (LocalScript) to do the job you need it to do.
However, if you wanted something to happen for the entire server, but it’s controlled from 1+ user’s screens, then you would need the server.
TL;DR: Depends, but if you aren’t trying to submit information from a user’s client to the server, then there is no need.
I was just planning to do it for any pop-up GUIs I send to the clients, but maybe it would be best to leave them on the client and just toggle visibility/transparency/position as needed. Thanks for the suggestions.