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

How to find which script remote event was fired from?

Asked by 1 year ago

I really don't want to make a bunch of remote events. How would I make the script know where which script fired it?

0
You can’t, unless you set the script as an argument. T3_MasterGamer 2189 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago

When you fire a remote event, you can put strings, integers or anything in them example:

RemoteEvent:FireServer('hello', 1, true)

And in the script that receives the event, you can do this:

RemoteEvent.OnServerEvent:Connect(function(player, string, integer, bool) --you have to add 
--player at the start or it wont work
print(string) --output will be "hello"
print(integer) -- output will be 1
print(bool) --output will be true
end)

With all that, you can do this:

--localscript
RemoteEvent:FireServer('script1')
--script
RemoteEvent.OnServerEvent:Connect(function(player, scriptname)
      if scriptname == 'script1' then
         print('hello')
         end
end)

Note: if you want to do it from the server to the client, you have to first do: FireClient() instead of FireServer() and second, you have to include the player in the FireClient()'s brackets example: FireClient(game.Players.jedistuff2, 'script1')

Ad

Answer this question