My game is FE enabled and when I delete a cloned player gui locally, it is still there in the server explorer. How do I delete it on the server-side using remote events? StarterPlayerScripts don’t work with ordinary scripts.
As far as I know, the server can’t read the contents of PlayerGui at all – in fact, I don’t believe it can do anything except add GUIs into it.
Is there a reason you need to delete the server’s POV? Everything you need to modify it (and any reasons for doing so) should all be client-side.
To answer your actual question, what you’d do is use RemoteEvent:FireServer()
on the client, and listen to RemoteEvent.OnServerEvent
on the server.
Here’s an example:
-- Client
RemoteEvent:FireServer("DeletePlayerGuiContents")
-- Server
RemoteEvent.OnServerEvent:Connect(function(Player, Request)
if Request == "DeletePlayerGuiContents" then
Player.PlayerGui:ClearAllChildren()
end
end)
I used a slightly more advanced method – the ‘Request’ stuff – so you can make less RemoteEvent objects if you have lots of different server-client code you want to be done in the context of GUIs.
To make it as simplest as possible, just remove the ‘DeletePlayerGuiContents’ string from the client-sided code and remove the if-statement and the ‘Request’ argument from the server-sided code.
I know that I need to use remote events, but where should the remote and script be placed?
It doesn’t really matter where you place them, but if you want to find everything easily you should put the script in ServerScriptService and the remote can be placed anywhere as long as the client and the server can access it, Replicated Storage as an example.
If you need the Server to see the Guis for some reason you will have to Parent it to the Player with a Script, because when it’s in StarterGui and Cloned it’s Cloned with a LocalScript so of course the Server doesn’t see it.
I think we would be able to help you achieve what you want more easily if you Answer that.
It does matter, a lot (although out of the valid options, it doesn’t heh).
Places that both the server and the client can access (e.g. ReplicatedStorage, Workspace) will be fine to use for putting Remotes in. I recommend ReplicatedStorage, because it is good for organisation and dumping stuff.
The server-sided script can be anywhere, as long as it can run. Like Drolerina suggested, ServerScriptService is a good place.
Where the scripts are is fairly unimportant as long as they run, and are on the correct ‘side’ of the game.
It’s the same deal with remotes – they must replicate to both the server and the client, and they must be accessible by both of the scripts.
Hey,
What you’re doing really isn’t the best practice!
You should handle UI running locally always. If you need to remove an item, send that over a Client Event to signal that a Local Script should perform that action.
You can read more about that on the Developer Hub post on Client and Server-Side Scripting