Recently, I came upon few articles about a scripting concept called Object Oriented Programming. This topic, although daunting, was actually pretty easy to learn. After making a few object classes and tinkering with them I settled on making a small cube system. This was then when I encountered a huge issue with the code; unlike other issues, this one would complicate the project if not dealt with. One of the bindable events wasn’t working, this event was linked to the custom event and was mainly why I started this.
--CubeModule, ReplicatedStorage
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = BindableEvent
local Cube = {}
Cube.ClassName = "Cube"
Cube.__index = Cube
function Cube.new()
--Set Events
local HeldEvent = Instance.new("BindableEvent")
local newCube = {
Held = HeldEvent.Event
}
setmetatable(newCube,Cube)
--Fire Events
Event.Event:Connect(function(holder)
HeldEvent:Fire(holder)
end)
return newCube
end
return Cube
--TestScript, ServerScriptService
local cube = require(CubeModule)
local new = cube.new()
Event.Held:Fire("Testplayer123")
new.Held:Connect(function(holder)
print(holder) --prints TestPlayer12
end)
If anybody is willing to, please help with the bindable event.