Multiple Remote Events vs Single Remote Event?

So I’m writing an inventory script for my game. However, I don’t know whether or not it’s better to use a single remote event, with a “Request” argument, or multiple remote events for each function.

In the code below, you can see that I have created a single remote event listener which runs a certain function based on the “Request” argument.

I could just create multiple remote events and multiple listeners for each function, but I thought it might be more optimised to have a single one. I have very little knowledge of game optimisation, so can anyone with the right knowledge advise me on which option is best?

Inventory_Query_EVENT.OnClientEvent:Connect(function(Input, Request)
	if Request == 'GenerateInventory' then
		GenerateBolts(Input['Bolts'])
		GeneratePets(Input['Pets'])
	elseif Request == 'RemoveBolt' then
		RemoveBolt(Input)
	elseif Request == 'AddBolts' then
		AddBolts(Input)
	elseif Request == 'RemovePet' then
		RemovePet(Input)
	elseif Request == 'AddPets' then
		AddPets(Input)
	end
	
	
end)
2 Likes

it doesn’t really matter unless you’re firing them more than 20 times a second, which is the limit. i would use multiple remote events for organization.

3 Likes

Ah okay, is there any way to ensure that limit is never met?

1 Like

… don’t fire a remoteevent more than 20 times a second. don’t fire any events in a fast loop unless you are completely certain that it wont get over the remoteevent limit

“Game Optimization” is a pretty broad term. There are tons of ways to “optimize” your game… that doesn’t mean you will want to do so. Why? Because most developers make the mistake of caring about whether or not exploiters can cheat in your game. Which is fine but then you can’t complain about performance. So you ask, which option is best when it comes to performance? Making your game as exploitable as humanly possible. The more vulnerabilities there are… the better your performance will be. I’m sure people will reply to me saying that exploiters can crash and lag servers, who cares. I’d assume that would be only 5-10% of servers? Even if the percentage is higher, still doesn’t matter. Majority of servers will be clean and great performance will draw far more visitors to your game compared to one that doesn’t.

Inventory_Query_EVENT.OnClientEvent:Connect(function(Input, Request) like use
notif:FireClient(plrs,script.Parent:GetAttribute(“Title”),script.Parent:GetAttribute(“Text”))
notif:FireAllClients(script.Parent:GetAttribute(“Title”),plr.Name … " "… script.Parent:GetAttribute(“Text2”))

– Connect the Inventory_Query_EVENT’s OnClientEvent to a function
Inventory_Query_EVENT.OnClientEvent:Connect(function(…)
– ‘…’ represents any arguments that are passed from the server when the event is fired

-- Retrieve arguments passed from the server
local args = {...} -- This will store all arguments in a table if there are multiple

-- Example of handling specific arguments
if #args > 0 then
    -- For example, let's assume args[1] is an action and args[2] is an item
    local action = args[1]
    local item = args[2]

    -- Handle different actions based on the first argument
    if action == "AddItem" then
        print("Adding item to inventory:", item)
        -- Add your code here to add the item to the player's inventory

    elseif action == "RemoveItem" then
        print("Removing item from inventory:", item)
        -- Add your code here to remove the item from the player's inventory

    else
        print("Unknown action:", action)
    end
else
    print("No arguments received from Inventory_Query_EVENT.")
end

end)

but fireserver it need player OnServerEvent(player,…) on script because if u use a gui

tl;dr
It really just doesn’t matter unless you are making the client send 20 events to the server as @MikeartsRBLX also mentioned.
Do it however you’d prefer, no one is going to judge you for using remotes that way. (unless you are working with other developers :sweat:)

Just know passing everything in one remote improving performance is in fact a big hoax.
Heres what Quenty at RDC 2020 had to say about it: https://youtu.be/Db3LooLQM1Q?t=398
I’d suggest you watch this.

1 Like

Wow thanks for sending me that video. I think it’s actually worth me watching the whole thing because I’ve recently been wanting to improve my scripting skills. Although, that video does seem pretty confusing. (not the remote event part tho, thanks)

1 Like