Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can 1 script and 1 RemoteEvent handle any Event fired?

Asked by 6 years ago

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

0
"These" are passed to the OnServerEvent as arguments Amiaa16 3227 — 6y
0
?? CarlPlandog 20 — 6y
0
yes you can do that.. just use if loops to detect what is happening... greatneil80 2647 — 6y

1 answer

Log in to vote
0
Answered by
joeldes 201 Moderation Voter
6 years ago
Edited 6 years ago

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.

0
You forgot the second 'then' on the Server Script but thank you!! CarlPlandog 20 — 6y
0
oops! Thanks for catching that! I was having a bad typing day when writing that :) @CartPlandog joeldes 201 — 6y
Ad

Answer this question