How would I go about creating my own custom event? I have no idea how to do this and it would be cool if I can.
If you mean without the use of BindableEvent | Roblox Creator Documentation or Functions | Roblox Creator Documentation, then no. If you simply just want to fire an event when something happens then use BindableEvent:Fire(whateverYouWantToPass)
and connect it with
BindableEvent.Event:Connect(function(whatYouPassed)
end)
This functionality has already been implemented. I suggest utilizing FastSignal, and if perhaps you want to substantially modify it, fork the repo.
1 Like
GetPropertyChangedSignal("Property")
even though this isn’t a custom event this should pretty much cover all bases.
You can use Bindable events for general events, as mentioned.
But if you mean how you can do that in OOP:
local newClass = {}
newClass.__index = newClass
function newClass.new()
local self = {};
self.random_event = Instance.new("BindableEvent") -- // You will need this reference, otherwise how will you fire the event.
self.Randomized = self.random_event.Event -- // You set the event name equal to BindableEvent.Event, this is your event
return setmetatable(self, newClass)
end;
function newClass:Call()
self.random_event:Fire() -- // You can fire the event.
end;
function newClass:ConnectEvent()
self.Randomized:Connect(function() -- // You can create a connection to the event.
print("Event fired.")
end)
end;
return newClass