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

Can 1 script and 1 RemoteEvent handle any Event fired?

I have this script, and inside it there is a RemoteEvent. I was wondering if there was a way it could be multi purposed? So if you fire it, It would be like this

game.ServerScriptService.Script.RemoteEvent:FireServer("Event")

And then you could fire the same remote but with something else like this

game.ServerScriptService.Script.RemoteEvent:FireServer("EventSameScript")

But if you can, how would you detect these?

Thanks

3 comments

0

"These" are passed to the OnServerEvent as arguments

0

??

0

yes you can do that.. just use if loops to detect what is happening...

1 answer

✓ Accepted answer

In short... Yes.

If you wanted, you could have one RemoteEvent that listens for a hypothetical PacketId. When you Fire the remote event, you would send a PacketId as your first argument and then the rest of the data. Here's an example.

On the server it would look something like this:

game.ReplicatedStorage.Remote.OnServerEvent:Connect(function(player, packetId, ...)
	if packetId == 1 then
		-- Do somthing
	elseif packetId == 2 then
		-- Do another thing
	end
end)

Obviously, you don't have to handle all the packetId's on the same script.

Then on the Localscript you would do this:

game.ReplicatedStorage.Remote:FireServer(1, stuff, moreStuff)

-- OR YOU COULD DO

game.ReplicatedStorage.Remote:FireServer(2, stuff, moreStuff)

If you liked this post, please upvote and accept. I'm tryin to get that rep.

2 comments

0

You forgot the second 'then' on the Server Script but thank you!!

0

oops! Thanks for catching that! I was having a bad typing day when writing that :) @CartPlandog

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