An easier way to communicate between client-client and client-all clients (RemoteEvents)

Turkish explanation: https://www.gelistiricitoplulugu.com/d/169-client-to-client-iletisimi-hizlandirmak-icin-basit-bir-yontem

Please note that it is not safe, exploits can ruin the whole game because of that. Just use it if you want.
Hello epic peeps. I guess you are here because you want to communicate between client to client or client to all clients.
Well, I found an easy way to do that. That requires simple scripting but it will be extremely easy to send an information to client or all clients.
So let’s see the hard and boring way to communicate between client-client.
welp, it still work like client-server-client.

-- CLIENT 1's LOCAL SCRIPT
RemoteEvent:FireServer() -- Send info to server
-- SERVER
RemoteEvent.OnServerEvent:Connect(function(Player) -- Gets info from client
RemoteEvent:FireClient(Player)
end)

-- CLIENT 2's LOCAL SCRIPT
RemoteEvent.OnClientEvent:Connect(function()
print("Info received!")
end)




Yeah, that is the boring way to communicate between client-client.
Alright so let’s get started.
First we need to setup a remote event for handling.
That remote event is way too important because we will use this to send information between the whole game. Anyways, just name that remote event to ClientSender (u can change it tho).
By the way I assume that you put that remote event to ReplicatedStorage. By the way I’ll also allow you to send infinite informations with remote events too! Anyways so, we need to create a script to server script service to handle the events.

I’ll write a simple handling script and tell you how it works.

local informationHandle = game.ReplicatedStorage.ClientSender -- The location of the remote event that we created before.

informationHandle.OnServerEvent:Connect(function(senderClient, RemoteEvent, FireType, receiverClient, ExtraInfo)
-- senderClient is the client that we receive info from.
-- RemoteEvent is the RemoteEvent that will be fired.
-- FireType is the type of the call event. ex: "FireAllClients" or "FireClient"
-- receiverClient is the client that is going to receive information. If your fire type is "FireAllClients" then you can make it nil.
-- ExtraInfo is the info that we are sending, if you are going to send over 1 info, you need to make it as table.

if FireType == "FireClient" then
if receiverClient ~= nil then
RemoteEvent:FireClient(receiverClient,ExtraInfo)
else
error("Error sending information to client: ClientReceiver can't be empty.")
end
elseif FireType == "FireAllClients" then
RemoteEvent:FireAllClients(ExtraInfo)
else
error("Error sending information to client: FireType is not valid")
end



end)

Yeah! That’s it. So let’s test it.

Client 1:

local messages = {
["Message1"] = "Hello",
["Message2"] = "Hi"
}
game.ReplicatedStorage.ClientSender:FireServer(game.ReplicatedStorage.MyEvent,"FireClient",game.Players.Player2,messages)

also I can use FireAllClients. But I need to make the player thing (receiver) to nil.

Client 2

game.ReplicatedStorage.MyEvent.OnClientEvent:Connect(function(receivedMessages)

print(receivedMessages.Message1)
print(receivedMessages.Message2)

So the output will say “Hello” and “Hi”.
That made the communication faster than I showed in first paragraph.
Let me know if you need help.
Thank you for reading.

this seems very insecure, this would allow clients to fire any RemoteEvent with any data the client wants to any player the client wants, meaning an exploiter could mess with them to do unintended things, like for example (in a round based game) tell another client that a round started even though it didn’t, potentially breaking the game for that player

edit i just noticed the exploiting risk warning at the top of the post, i’m not sure if that was edited in, but i didn’t see it sorry

Yeah I forgot to say it, another friend said the same lol.
But you can use it if you want.

I just edited it recently while ur typing your reply :stuck_out_tongue:

Pretty good tutorial, but it’s just the same thing, but more complicated. I think the normal way of the client firing to the server and firing to all clients with a single remote is better because you can implement individual sanity checks on the server to make sure exploiters aren’t messing around with the remote.

1 Like