You can send object values in RemoteEvents?

I want to send an object value in a remote event, like send a player’s GUI, and you can find it’s descendants, parents, etc. For example:

Event:FireEvent(Player:FindFirstChild("Gui"))

Server script:

Event.OnServerEvent:Connect(function(player, gui)
    print(gui.Parent) --Player name
end)

But i don’t know if that is possible, thanks for reading.

1 Like

It is probably possible, have you tried searching it up?

Yes, but i didn’t found any thread or something useful to help me.

why are you even doing this? If you want to access the PlayerGui of a player use the first parameter from the event.

So it would be

Event.OnServerEvent:Connect(function(player))
 print(player.Name)
 local ui = game.Players:FindFirstChild(player.Name).PlayerGui:WaitForChild("YourGUIName")
end)
1 Like

because that question popped inside my mind lol

I don’t want to access the gui from the player, i want to know how to send that gui from the event and be able to access from it.

This is possible. For example, you can pass ‘player’ as an argument (or sometimes it’s needed by default).

I mean, you could send the GUI name and find it with the parameter in the player, then apply changes.

1 Like

Object values are indeed send able as arguments via RemoteEvents and RemoteFunctions BUT there are a few things you should be aware of.

  1. The server can not see what the client creates

There should be usually no reason for you to be sending an object value to the server (unless you have multiple similar objects and you wish to send a specific one). But I’m 99% sure that if the object was created on the client, the server will not be able to see it.

On the other hand, if the server was to create an object the client will see it because of replication as well as you can send the object to the client.

You can test these questions out by yourself by writing a “test” script and see if it works or not.

9 Likes

why would you do game.Players:FindFirstChild to get player when you’re passing player as an argument? The received parameter ‘player’ is the player.

Event.OnServerEvent:Connect(function(player))
 print(player.Name)
 local ui = player.PlayerGui:WaitForChild("YourGUIName")
end)

gui.Parent will return its parent not it’s name.
In this case you would have to do this :

print(gui.Parent.Name)

Edit : yes, you can give objects as parameters

Be 100% sure. Instances are passed by reference. Objects created on the client cannot be seen by the server, so the reference will be nil.

3 Likes

Just for clarification, where can I find this information on?

You will need some understanding of the Roblox client-server model which will lead you to this conclusion. Remotes don’t create new objects so instead they’re passing along variables that reference the object (much like how the game global variable references the DataModel). An object created on the client does not exist other clients or the server as per what the client-server model enforces, therefore it is nil and all such references point towards nil.

1 Like

I had a hunch that was the case but I couldn’t be sure until I found an authoritative person’s reply on it.