Brief Explanation
As of now, each class(or Instance) has it’s own unique properties/attributes, but, it would be nice if we were to be able to add our own, theoretically adding to the instance. This will help developers because we wouldn’t need to use extra lines of code to execute simple tasks.
How will this work?
There will be a button at the bottom of the properties tab that will ask you if you want to create a new property or not:
Then, once you click on it, it will bring you to another interface, naming the property, what value it is, etc.:
Value type is the type of value(string, int, number, adornee) the new property will be. Name is the name of the property, and apply global is if you want to apply this property to all instances of the same class(if set to true), and only local to the part(if false).
Step 2 of Creating a Property
One you do it, it will bring you to the script editor, where you will be able to script what the property does. For this example, consider these variables:
- Value type is an IntValue
- Name is DamageOnTouch
- Apply global is false(Meaning affecting this part only)
- Property added to a MeshPart
This is what it would look like:
As you can see, you can add more than one property. And you can edit the code with the “Edit” button.
The script editor will assume that this is an int value, which you can reference with a new variable Property
. So, if we do print(Property)
and the Property is 10 it will print 10
. PInstance
will be the reference to the Instance that the property will be added to.
So, let’s say the property was equal to 10, and I apply this following script to it:
local HitTimes = 0
PInstance.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
Humanoid:TakeDamage(Property) -- Humanoid takes 10 damage
HitTimes = HitTimes + 1
PInstance.Name = HitTimes -- Of course, you can still modify the instance
print(HitTimes)
end
end
Now, whenever the part is touched it will make the player take 10 damage, make the name of the object the amount of times it damaged a player, and print it out.
Why this?
This will dramatically shorten code work, because this code will be embedded into the property. no need to worry about scripting it anywhere else. Say goodbye to metatable
s for doing this. This will also make work faster because you don’t need to scroll through an endless amount of code to find one thing, and modifying it will be at ease.
Sneak Peek: