Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how can i use 1 remote event/function for multiple things?

hi, i want to make a remote event or a remote function to change color of a part in workspace with a gui. instead of me having to make a remote event/ function for each of the color how can i make it so that only 1 remote event / function is needed? will i have to use InvokeServer()???

anyhelp appreciated. Thank you.

1 answer

✓ Accepted answer

All you have to do is send a command as the first argument in the call, and use a variadic function to include any other arguments (in this case, the colour). As an example:

Server-Side

local remote = Instance.new('RemoteFunction', game:GetService('ReplicatedStorage'));
remote.Name = 'Utility';

local part = workspace.WhateverThePartIs;

remote.OnServerInvoke = function(player, command, ...) --// ... used here makes this a variadic function. Link to an explanation is at the bottom of this answer.
	local args = {...} --// Turn the extra arguments into a table.
	if command == 'colour' then
		local colour = args[1]
		if type(colour) == 'string' then
			part.BrickColor = BrickColor.new(colour); --// Ideally, you'd check if it's a valid colour with a table. Skipping this for the example.
		end;
	end;
end;

Local

local remote = game:GetService('ReplicatedStorage'):WaitForChild('Utility');
remote:InvokeServer('colour', 'Really red');

Really, that should be all there is to it. Here are some links, I recommend you read up on what was used in this example so you can fully understand it. Hope this helped!

Remotes, Variadic Functions, BrickColor

1 comment

0

Ty for your help.

This discussion is preserved as it was. New answers, comments, and votes are closed.