One RemoteFunction for each function?

Just to confirm, for me to call a function between Server and LocalScript and vice versa, will I have to have a RemoteFuncion or RemoteEvent for each function?
Does this mean that if I have 100 functions, I will have to create 100 RemoteFuncion/Event for each one, in ReplicateStorage?

That’s right?

You could put them all in a dictionary and send the option for the script to look it up

Server:

local Options = {}
function Options.Hi(Player, ...)
	print("hi", Player, ...)
end
function Options.Bye(Player, ...)
	print("bye", Player, ...)
end

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player, Option, ...)
	local Function = Options[Option]
	if not Function then					print("Invalid")				end
	
	local Success, Err = pcall(Function, Player, ...)
	if not Success then				print(Err)				end	
end)

Client:

game.ReplicatedStorage.RemoteEvent:FireServer("Hi", "its me")

The pcall is optional, so the script is not broken.

2 Likes

Using a separate remoteevent/-function for each function also works fine, it’s mostly up to preference, but I would say passing an argument like in the example above is much cleaner.

1 Like

And why not a combination of both? So there are not many ifs and it is easy to add more related functions.

2 Likes

That’s really a great solution and saved me a lot of work.
Thank you very much! :+1:

1 Like