I’ve created a system of two methods which will control a series of BindableFucntions to create random events that will happen in-game. To do this I’m using a ModuleScript to setup the main system, and a script that will bind a set of additional ModuleScripts parented under a folder into the system itself.
This is called by requiring the original ModuleScript, then using the :BindRandomEvent() method to bind a function which will then be tied to a BindableFunction, and stored in a folder under ServerStorage.
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Events = require(ReplicatedStorage.Modules.RandomEvents)
local required = require(ReplicatedStorage.RandomEvents.PrintMessage)
Events:BindRandomEvent(required.Bind, 'PrintMessage')
In this code I am using a function tied to “Bind” to bind to the BindableFunction.
local PrintMessage = {}
PrintMessage.Bind = function(message)
print(message)
end
return PrintMessage
In this sense, you could bind multiple functions into the folder, and fire them from the same script by calling :FireEvent(). You give the BindableFunction a “tag” which will reflect its name, which then you could use :FireEvent(tag, args?) to fire the given event alongside any arguments.
Events:FireEvent('PrintMessage', 'Hello World!')
What I am largely trying to accomplish is something that is reliable and works fast. I would like to find a better way to format the code, and try to introduce things like Parallel lua into the overall system itself.
RandomEventsFramework.rbxl (43.6 KB)