Send Client's PlayerGui To server?

Does anyone know how I can send Client’s PlayerGui to Server so the server and Player have the same PlayerGui?

For example, I have a ScreenGui and I Add a Child to it on the server, how could I update the server so it will see the Child that was added to it?

You could just use a ChildAdded event on the PlayerGui

game.Players.PlayerAdded:Connect(function(Player)
    local PlayerGui = Player:WaitForChild("PlayerGui")

    PlayerGui.ChildAdded:Connect(function(NewChild)
        print(NewChild)
    end)
end)

If you wanted to detect the change from the client, you’d need to use a RemoteEvent to fire the new child added from the client to the server

I would not be able to use a RemoteEvent, because if I tried to send the ScreenGui from the Client it would just be a reference and still be the Servers ScreenGui, I also can not send objects through a RemoteEvent Argument.

You’re code is not related to what I am trying to accomplish, you’re code is saying everytime a Child is Added on the server side of my gui to print. So therefore if there was any change on the Client, the server would still not be updated.

I know what you’re looking to accomplish, but it’s a lot of work to send serialized versions of instances to the server, and then deserialize them. Additionally, it also requires a lot of input validation to be secure.

What exactly is your use case? You should never need to change the client’s ui from the server.

Likely what you’re looking for is using remote events to send data to the client for it to display.

You can try to use a RemoteFunction | Roblox Creator Documentation to return the object to the server

and just get its properties

This won’t work for his use case as client-created objects are not replicated to the server. The proper solution would be to send properties to the server using a RemoteFunction instead, though I’m not sure if that would solve OP’s actual problem.

No, Im trying to send data from the client to the server for a datastore, I usually would just check if anything ChildrenChanged but Im using the event and it does not seem to be working, thats why Im trying to send the data to the Server from the client instead.

If thats the case I will end up making the changes on the Server Instead that way the Server and Client are aligned.

How so would I accomplish this sort of task?

Why exactly do you need to listen to children changing? If you’re the one modifying them, just send data to the server at the same time.

Example code that might help

SomeButton.Activated:Connect(function()
    SomeButton.BackgroundColor3 = SomeSelectedColor
    SomeRemoteEvent:FireServer('selectedButton', 1)
end)
1 Like

I need to check when a new TextLabel is added to the “Messages” folder.
https://gyazo.com/06a1d77b79ff74738cee67f9e7cc492f

Actually I might have got an idea of this.

Why does the server need to know anything about the children of the clients gui? Normally we leave the client to handle all things gui-related.

You could use ChildAdded, but if you’re the one creating the messages you could also put the code there. Both ways would work; It just tends to be cleaner to have less event connections if you can easily avoid them.

Example Code For ChildAdded
yourFolder.ChildAdded:Connect(function(child)
    --Do something with child, like
    child.TextColor = Color3.new(1,0,0)
end)

I am handling that on the client, I don’t recall saying anything about that happening on server.

For example, I have a ScreenGui and I Add a Child to it on the server

I add the child on Client, I want the Client to be updated too. Its also a 1 player Server.

All I can say as of know the only Solution, is to make the changes on the Server.

2 Likes