Can you use multiple remove events?

Can I use a remote event in one script, and use another in another script or function?
Or do I need to make separate RE’s for each function?

2 Likes

You can use 1 (depends), you can use 500 (not recommended but possible), any amount you need for anything. It doesn’t matter, use how many remote events you need to handle certain things, you can have a certain remote event handle certain gun functions, another for minigame functions, or 1 for both.

Just dont go overkill of course.

3 Likes

But can I use the same remote event for multiple functions, unclear on that. Are you saying I can tie multiple functions to the same remote event, or only use 1 function per RE?
I’m still new to this concept. Thanks.

And also, can a server script affect a players backpack or does that have to be done on the client side?

Yes you can use the same remote event for multiple functions. Client side and server side can effect it but it changes, client sided changes only effect client things, server side effects client and server.

It really depends on how you handle your remote events, they’re just “connections” to help communicate certain functions and actions.

You can have a parameter in your remote event that is basically an identifier of what you want the remote to do, then when you decide what you want to do execute that function. I recommend to use less remote events than to have 100+ to just do simple functions.

I would not recommend to use too many remote events unless they are fully secure, the more remote events you have the more vulnerabilities your game is susceptible of.

Yes you are able to do that for example

--client side
game.ReplicatedStorage.RemoteEvent:FireServer('type1')
game.ReplicatedStorage.RemoteEvent:FireServer('type2')
game.ReplicatedStorage.RemoteEvent:FireServer('type3')

--server sided
game.ReplocatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, typeOf)
    if typeOf == 'type1' then

    else if typeOf == 'type2' then

    else if typeOf == 'type3' then

end
end
end
end)

This is just my way of doing it

1 Like

Something I’d like to mention, dont let the client have too much control over the remote events since its on client, they can manipulate and change things. Important arguments should be handled only on the server rather than on the client, just a side note to add onto that ^ :+1:

2 Likes

You can either handle everything inside one event, like this:

local Event = game:GetService('ReplicatedStorage').Event

Event.OnServerEvent:Connect(function(Player, Check, ...)
	if Check == 'Update' then
		-- Deal with update stuff
	elseif Check == 'Add' then
		-- Deal with add stuff
	elseif Check == 'Remove' then
		-- Deal with remove stuff
	end
end)

Or, have seperate events like this:

local Replicated = game:GetService('ReplicatedStorage')
local Update = Replicated.Update
local Add = Replicated.Add
local Remove = Replicated.Remove

Update.OnServerEvent:Connect(function(Player, ...)
	-- Update
end)

Add.OnServerEvent:Connect(function(Player, ...)
	-- Add
end)

Remove.OnServerEvent:Connect(function(Player, ...)
	-- Remove
end)

Personally, I would go with the first example as that is more efficient.

1 Like

As 3rdhoan123 said, it is possible. The problem with that is that it is extremely hard to manage. However, if it’s 1-9 remote functions, then putting it on a single script is great to remove space. If it’s more, i’d say to do it on a new script.

Just a reminder that the client has full access over your remote events (Client sided), so they can plug in any data into its parameters and fake actual data. This is why you have sanity checks to make sure your remote events are secure.

1 Like

What is a sanity check?

And another question, I’m trying to remove a players items from his backpack.

How do I remove his items if he has the item equipped?

A sanity test or sanity check is a basic test to quickly evaluate whether a claim or the result of a calculation can possibly be true.
It is a simple check to see if the produced material is rational (that the material’s creator was thinking rationally, applying sanity).

1 Like

can you give an example please?

Roblox engineers recommend that it is better if you use multiple remote events rather than using only one, here is a link to the video https://www.youtube.com/watch?v=rBrILsiVdtQ&list=PLuEQ5BB-Z1PLWg482ka-M0XVCNWKrv8zq&index=16 (go to 37:20).
So basically if you use one it will use more bandwidth because your having to send more data over that one remote event, so i recommend you do not use @Xueify’s approach. There is nothing wrong with using a decent number of remote events it makes your code more readable since you know exactly what each remote is doing. Also, yes technically you can connect the same remote event multiple times on the server, but if your doing that then your most likely doing something wrong, it is ideal to have one remote connection for each event on the server and client at most one time so you know exactly where to go when something is not working, in regards to that remote event.

2 Likes

yea, you should never believe the client in these types of choices because it can, depending on the game spoil the gaming experience of others or even destroy it

It depends how many RemoteEvents you are using in your game, if you had like 10,000 RemoteEvents and everything was handled in one script, it would be better to have 1 script for each RemoteEvent as it uses less bandwidth.

I don’t understand what your are saying, before you were saying to use one remote for multiple purposes. The bandwidth is affect by the amount of data you send over the remote not how many scripts you use to handle the remote event.

1 Like

Use whatever that is most readable, both methods are acceptable.
But in practice, having one event per function is better, instead of firing a single remote everytime a certain action is performed.

can you give an example of a sanity check?

local Event = game:GetService('ReplicatedStorage').Event

Event.OnServerEvent:Connect(function(Player, ClientArgument)
   if ClientArgument == 'Hello' then
      print(ClientArgument)
   end
end)

In this case, we do a sanity check on the server to ensure that the client hasn’t sent something else, it will only be true if what is being sent = Hello.

EDIT: You can also choose to kick them if the sanity check is false.