RBX built in events

I had this a question for a long time, are built in events/listeners such as this:

Instance.Changed:Connect(function()

end)

ran with loops? Like in the core scripts are there loops constantly checking if a condition is met and then fires the event?

To the best of my understanding, that is not the case.

For instance, in the case of Changed, when a property is given a new value, that value is passed through the set function for that property. Alongside updating the internal value for the property, that function also calls any callbacks assigned to it, which would be your connected event listeners.

For a less clear-cut example, consider Touched. When the physics engine runs its calculations to move parts around, it may find that the new location of a moving part would cause it to intersect with a different part, which is in-essence a collision at the lowest level. The engine needs to recalculate valid positions and apply forces related to the collision to both parts, and in this code block Touched listener callbacks can be called.

Of course, a lot of your RunService event listeners are effectively loops, but that is the service that drives logic within the runtime environment, so that makes a bit more sense.

2 Likes

What is the set function? What does it do?

The set function would be written into ROBLOX’s underlying engine. That’s what they are called in C#, although I don’t remember specifically what language ROBLOX’s engine uses.

Set and get functions allow for the creation of properties in C#, but you don’t need to worry about them in the Lua used for making your games, they’re just what’s going on under the hood. Your Lua code goes “on top” of the base engine, so to speak.

2 Likes