How to handle client to server communication in my game with only 1 remote

In essence I basically want to just have one remote and it can handle everything; because I dont want my game to be cluttered with many remotes and have random initializes of remotes

2 Likes

Well, as usual I guess? Just send information through…
Maybe some table that describes everything, and then you check it on server. Nothing special? Just recommending using modules, so that the code is not a mess.

Client
local Event
local table1 = {
Move = "Buy";
Arguments = {Item = "Pizza"};
}


Event:FireServer(table1,more arguments)

or

local Event

local table1 = {
Move="UserInput";
Arguments={KeyCode="",Proccessed=false};
}

Event:FireServer(table1)
Server
local Event
local Shop = require(script.Shop)

Event.OnServerEvent:Connect(function(Player,args1,...)
  local additionalArguments = {...}
  if args1.Move=="Buy" then
        Shop.Buy(args1)
  end  
end)
1 Like

Well, send a paramater string that tells what you gonna do, like “Die” and is the remote but when the player dies, etc

Using only 1 remote to handle everything in your game isn’t like a very good idea telling that you need a ton of if condition then, the use of unnecessary varargs, and it might decrease performance.

-- client
remote:FireServer(1)
-- server
remote.OnServerEvent:Connect(function(plr, ...)
    local args = {...}

    if args[1] == 1 then
      -- do stuff
    elseif condition then
      -- do things
    end
end

Remote.OnServerEvent passes the player who fired the remote first, not the first argument that was sent through the event. That would be the second argument

I believe F3X does something similar to this. If you want you could get the free model of the F3X tool and take a look inside of their scripts. They have one or two remote functions for the entire tool with many scripts.

Yes, thanks for pointing that out, I edited the message now it’s fine. Just forgot about that one :sneezing_face:

1 Like