It’s pretty easy once you know how.
First you have to set up like the “Phone line” between the two. I do this in my control script. My object that controls all the core workings of the game. Server side.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerToClientEvent = Instance.new("RemoteEvent", ReplicatedStorage)
ServerToClientEvent.Name = "ServerToClientEvent"
local ClientToServerEvent = Instance.new("RemoteEvent", ReplicatedStorage)
ClientToServerEvent .Name = "ClientToServerEvent "
So now you have the event in Replicated Storage.
Now you use the phone line.
So a server script like a button will be the object you use to open the gui object of the player. Say a teleport. You stand on it and it triggers code for the player.
The button you stand on has a script and on the touch connect event, you get the player name.
ServerToClientEvent:FireClient(Player, Message1)
That there sends a message to the client, the Player. So you get the player identification and put it into the Player variable. And what ever you want into the Message. Like 1 for portal 1.
The client’s Gui script (localscript) then recives the message:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerToClientEvent = ReplicatedStorage:WaitForChild("ServerToClientEvent")
local ClientToServerEvent = ReplicatedStorage:WaitForChild("ClientToServerEvent")
local function onServerToClientFired(Message1)
MyMessage = Message1
--other code here.
end
ServerToClientEvent.OnClientEvent:Connect(onServerToClientFired)
Now say there is a button on the gui that is tweened onscreen. You click the button and it will fire the ClientToServerEvent.
ClientToServerEvent:FireServer(Message2)
The server script will then have like:
local function onClientToServerFired(Player, Message2)
InfoFromPlayer = Message2
-- insert other code here
end
ClientToServerEvent.OnServerEvent:Connect(onClientToServerFired)
Notice that the server stuff has “OnServerEvent”
And the client stuff has “OnClientEvent”
Notice that the Client auto sends it’s Player ID with the message.
Notice the Server NEEDS the player ID to work out who to send the massage too.
The player doesn’t need to know which player it was sent to so it’s first message is the actual message.
The server needs the player name so that player name is the first message it gets in the event.
It’s pretty easy once you know how.