As a Roblox developer, it is currently too hard to create individual objects that we can assign to an instance to give it extra functionality (can be considered as DOP or Data-Oriented Programming).
Why Components?
Components can help developers organize their frameworks, and make it easier for them to understand what a specific object does. Components also allow developers to edit variables within the components during runtime that alter what the component does. This system will give developers an extra way to design their frameworks, similar to how many of them already use OOP as their framework of choice.
Popular game engines such as Unity already have this feature implemented:
A topic about this feature:
How Does it Work?
Components will work exactly like Roblox’s classes system; an ImageButton inherits from the classes: GuiButton, GuiObject, GuiBase2D, and Instance. Thus these classes add on to what the ImageButton actually does (displays an image on a frame).
The interface for inserting different components would be similar to adding attributes:
When the “Add Component” button is clicked, it will bring up a menu with the same design as the Insert Object menu but instead of every instance, it contains every component. Component names derive from the name of the ComponentScript that the component runs on.
To create a component, insert a ComponentScript into a new service: ComponentService:
--// In the ComponentScript named "Hitblox"
component = { -- "component" is a new global used specifically in component scripts
-- This is where the component variables are stored
Damage = 10
}
reference.SwordBlade.Touched:Connect(function(hit) -- "reference" is a variable of the instance that the component is attatched to
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid:TakeDamage(component.Damage)
end
end
In runtime, you can edit the component like this:
local Sword = workspace.Sword
local SwordBlade = workspace.SwordBlade
SwordBlade.Damage = 100 -- Just like how you would edit an instance's property
Why not CollectionService?
Though CollectionService allows you to assign “tags” which you can access the tagged instances and assign functions to them, it doesn’t provide a visual representation and it’s uneditable from other scripts.
If Roblox would add this feature it would improve my development workflow drastically as I’d prefer using small script chunks that I can add to my objects than full-fledged frameworks that can be hard to determine what it does and where it runs.