How to fire an event from server to server

I am making a killstreak system and was wondering how do i fire an event from serverscript to another serverscript. I looked into bindable events and was kind of rly confused and was wondering if i cn use em for this

6 Likes

The easiest way is to turn one of those scripts into a ModuleScript instead, and require it in the other one.

For example,

Here’s the ModuleScript (maybe its in ServerScriptStorage):

-- Tables are store multiple values in one variable
local my_functions = {}

-- Add a few functions to the table
function my_functions.foo()
	print("Foo!")
end

function functions.bar()
	print("Bar!")
end

-- ModuleScripts must return exactly one value
return my_functions

And here’s the Script (also in ServerScriptStorage):

-- The require function is provided a ModuleScript, then runs
-- the code, waiting until it returns a singular value.
local my_functions = require(script.Parent.MyFunctions)

-- These are some dummy functions defined in another code sample
my_functions.foo()
my_functions.bar()

I do know about module scripts but this event is read by multiple scripts across the game and i cant rly put them in a module script

You could use BindableEvents, sure.

Stick a BindableEvent somewhere.

local be = game.ServerScriptStorage.BindableEvent

Call :Fire() on it to fire it.

be:Fire()

And .Event:Connect() to it to… connect it.

be.Event:Connect(function() print("yeet") end)
29 Likes

I know this is solved but I think you could use a RemoteEvent, fire to client then back to server.

Why would you relay it from the client when the client has no information to pass? If possible Server > Server is the best way to go since Remotes have vunerabilites, and adds an extra un-needed step into the process.

18 Likes