Still have questions? Join our Discord server and get real time help.
Log in to vote

How do I clone a gui to PlayerGui with a serverscript?

Asked by
0lyxz -3
3 months ago

So I have been trying to clone a gui into PlayerGui for all the players in the server but the gui won't show up where I want it to be.. I have made a script that fires by a remote event. Here is the script:

for _, player in pairs(game.Players:GetPlayers()) do
local playerGui = player.PlayerGui
local clone = game.Workspace.StatusGui
clone.Parent = PlayerGui
You can't. Hellnickell 0 — 3mo

1 answer

Log in to vote
Answered by 3 months ago

A couple of things: First, relocate where you store the Gui. Don't put it in workspace, some place like "Replicated Storage" will do nicely.

SERVER SCRIPT: write this block of code wherever it should be executed. Use a remote event.

remote_to_invoke = game.ReplicatedStorage.REMOTE_INSTANCE
gui_instance = game.ReplicatedStorage.GUI_INSTANCE
-- Invoke to all players

You may be able to use the instance directly but I haven't tested. For now, this script set will look for the instance by its name inside of ReplicatedStorage.


remote_to_listen = game.ReplicatedStorage.REMOTE_INSTANCE
player = game.Players.LocalPlayer

function attachGUI(gui_name)
    gui_instance = game.ReplicatedStorage:FindFirstChild(gui_name)
    if gui_instance then
    -- Replicate the gui into the players GUI
        gui_instance :Clone().Parent = player.PlayerGui
        print("Unable to find local copy of GUI '" .. gui_name .. "'")


Basically, it will listen to the remote being invoked, check through replicated storage for the gui name which was provided when invoking the client. Then either print an error message or replicate the GUI into player GUI

Where do I put the LocalScript? 0lyxz -3 — 3mo
StarterPlayerScripts ig YTRaulByte 259 — 3mo
Ok, you should know that the server CAN access the PlayerGui but not its descendants. This means that the server can drop clones in the PlayerGui but once it puts them in there it can't see those clones. BashCaster 2170 — 3mo
Oh, alright. But the gui won't show up in playergui with these codes. 0lyxz -3 — 3mo
View all comments (2 more)
RobloxWhiz, I'm following the general rule of UI's stated by madattak. "When working with UI’s, as a general rule, any changes to a Players GUI’s should be made by the player themselves, the client, and not the server." 0lyxz, write some print debugging and tell me what section of the code doesn't appear. Also check your explorer to see if it replicated to the player GUI YTRaulByte 259 — 3mo
The function in the local script does not fire, and the the gui does not show up in playergui'. 0lyxz -3 — 3mo

Answer this question