How can a Server Script communicate to another Server Script?

Hello Developers! I am making a game where I have a script called “Monster Spawn” in server script service that spawns NPCs when the match starts. Until the match ends or when every player dies.
There is another script called “Main Script” also in server script service. This script starts the match after intermission and also ends the match when there are no players. So how would I make it so that the Main Script can tell the monster spawn when the match has started and also when there are no players? I have tried looking it up on the developer but I didnt find anything on server > server communication. If this is possible can anyone please tell me how?

Use BindableEvents for this sort of communication.

local b = script.BindableEvent
-- script 2
local b = -- path
--> 1, 2, 3

Oh so how can I do that? Can you give me an example?

just create a bindableevent, place it somewhere you can access it, such as replicatedstorage, then you can add a variable referencing the bindableevent, then you could use the example provided above.

Baseplate.rbxl (18.5 KB) this is an example implementation.

Are bindable events like replicated events where you can fire them and then the other script knows that it has been fired?

I dont really understand how would you like fire them?

You call BindableEvent:Fire(arg, ...)


to invoke BindableEvent.Event.

Just to be clearer those numbers are the arguments I’m supplying to be used as parameters within the callback, which here is print.

Do you need to use those numbers to fire it or not. Because in my case, I dont need that I just need it to know when everyone dies and when the match starts.

function callback( a, b, c )

BindableEvent.Event:Connect( callback )

BindableEvent:Fire( a, b, c )

If you don’t need arguments then you just wouldn’t supply anything in the parentheses.

function startMatch()

BindableEvent.Event:Connect( startMatch )

-- in your main script,
1 Like

Those numbers are just extra parameters he’s passing into the event, if you want the script that fires the event to be able to pass information to the script that is listening for the event, you’d have to do something like that.

-- Script 1
Bindableevent:Fire( "Hello!" )

-- Script 2
    print(Message) -- It would print Hello!

Why not take a look at the documentation? It has explanations, lists of methods, and example code.

I dont think it would need to send info because it just needs to know when the match starts and it will be programmed so that when it received the match start event it knows that the match has started. same thing for when there are no players. Tell me if im wrong though.

Its fine I mostly understand now but thanks for the help anyway.

Yeah, so in your case you wouldn’t have the need to send any extra parameters.

Ok so thanks a lot then. I will make it do that. And test if it works.

But do I do it like this?
or like this?

You call the method like you’re supposed to normally


What? What is that? I am confused and I need to be un-confused.

Fire is a method, you use it just like you would any other method, which means you’re meant to put parentheses after it

Oh ok but can I do it like this (As an example)?
script 1:
Bindableevent = game.ReplicatedStorage.TheEvent

script 2
Bindableevent = game.ReplicatedStorage.TheEvent
–do stuff