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

7 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)
48 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.

27 Likes

I dont like module scripts man they are so damn complex my tiny brain cannot comprend it :skull:

3 Likes

Its very simple. First, ignore the initial array that is formed, its required but you do not need to use it. Now, on to how they actually work.

A module script allows all scripts (Client and server) to access data and call functions inside of it. Think of it as the workspace, things changed or done by the server will replicate to clients, and things changed or done by the client will not replicate to the server nor other clients.

For example, lets say you have a module that contains a function. The function will take a basepart that has been passed through the call and move it left to right. If the server were to call it, it would shake the basepart for all clients. If a client were to call it, it would only shake for that client.