A module for actors.
The script you call the module from must be a child of a actor.
Source:
--> Dependencies
local Packages = script:WaitForChild("Packages")
local signal = require(Packages:WaitForChild("signal"))
local class = require(Packages:WaitForChild("class"))
local Actors = {}
--> Services
local RunService = game:GetService("RunService")
--> Class
local Class = class("Class")
--> Class Methods
function Class:__init(Actor, topic: string, callBack: () -> ())
if Actors[topic] ~= nil then return end
self.Actor = Actor
self.topic = topic
self.callBack = callBack
self.Connection = nil
end
function Class:Bind()
self.Actor:BindToMessage(self.topic, self.callBack)
end
function Class:BindParallel()
self.Actor:BindToMessageParallel(self.topic, self.callBack)
end
function Class:Send(...)
self.Actor:SendMessage(self.topic, ...)
end
function Class:Sync()
if self.Connection ~= nil then
self.Connection:Disconenct()
self.Connection = nil
end
self.Connection = RunService.Heartbeat:Connect(function()
task.synchronize()
end)
end
function Class:DeSync()
if self.Connection ~= nil then
self.Connection:Disconenct()
self.Connection = nil
end
self.Connection = RunService.Heartbeat:Connect(function()
task.desynchronize()
end)
end
--> Return Class
return Class
I made it because my friend gave me the idea but I honestly don’t know much about this stuff so