How do people make .Event:Connect(function(Thing)

Hello, so I’m working on a module. One thing i’m wondering is, how do certain modules make their own functions that are like:
Module.Event:Connect(function()
I can’t find anything about this, any help is appreciated

what you mean?
for example:

--Module script
Mod = {}

Mod.GiveMoney = function(player) -- don't forget to put it here
--your function, inside a module

print(player.Name .. "Wants some money")

end

return Mod

--Server Script
local ServerScriptService = game:GetService("ServerScriptService")
local Module = require(ServerScriptService:WaitForChild("YourModule")

game.Players.PlayerAdded:Connect(function(player) 
	task.wait(1)

-- this Function will activate the Function inside the MODULE

	Module.GiveMoney(player) -- you can send the player or some reference

end)



i don’t know if this is what u asked for , just guessing

Use bindable events

Those are BindableEvents you can find more about them here

--Script
local Module = require(script.ModuleScript)

Module.Event:Connect(function(...)
	print(...)
end)

Module:Fire("this is a test", 0, false)
--ModuleScript
local module = {}

local event = script:FindFirstChildWhichIsA("BindableEvent") or Instance.new("BindableEvent", script)

module.Event = event.Event

function module:Fire(...)
	event:Fire(...)
end

return module

PS: ... is a tuple containing all the parameters a function passes.

6 Likes

I love you, thank you so much bro

1 Like