The struggle of having Instance.new()
not support properties is quite an annoyance. Well, this module solves this issue by allowing you to create any instance with properties, attributes, and children with just one function!
đ Easy and Clean Configuration
This module uses arrays to edit the properties of an Instance. This allows for an easy and clean way to create instances.
For example:
Create("Part", {
Name = "Smart",
Parent = workspace,
Color = Color3.fromRGB(255,255,255),
})
You can also get the ValueBase instance with any values by using CreateVaseBase(Value: any, Properties: Properties?)
For Example:
CreateValueBase("StringType") -- Returns StringValue
CreateValueBase(2) -- Returns IntValue
CreateValueBase(2.22) -- Returns NumberValue
CreateValueBase(true) -- Returns Boolvalue
CreateValueBase(CFrame.new(1,1,1)) -- Returns CFrameValue
CreateValueBase(Vector3.new(4,4,4)) -- Returns Vector3Value
CreateValueBase(BrickColor.new("Really red")) -- Returns BrickColor
CreateValueBase(Color3.fromRGB(255,255,255)) -- Returns Color3Value
CreateValueBase(Ray.new(Vector3.zero, Vector3.yAxis * 100)) -- Returns RayValue
âĄPerformance*
NOTE: This is only in some test cases, SmartCreate is faster than Instance. new() in a few microseconds, but the speed is negligible.
Smart Create is much faster than using the ROBLOX Default method.
Test Case Code
ROBLOX Default
--Setting the property of part
local Part = Instance.new("Part", workspace)
Part.Color = Color3.fromRGB(255,255,255)
Part.CFrame = CFrame.new(1,10,0)
Part.Anchored = true
Part.CanCollide = true
Part.Size = Vector3.new(2,10,2)
--Setting the attributes of part
Part:SetAttribute("IsTouched", false)
Part:SetAttribute("DefaultSize", Vector3.new(1,1,1))
--Setting the Touched Event of the part
Part.Touched:Connect(function(otherPart)
print(otherPart.Name .. " touched!")
end)
Part:GetPropertyChangedSignal("Name"):Connect(function()
print("Name changed to "..Part.Name)
end)
--Setting the child of the part
local Head = Instance.new("Part", workspace)
Head.Size = Vector3.new(5,5,5)
Head.Anchored = true
Part.Parent = Head
SmartCreate
Create("Part", {
Name = "Smart",
Parent = workspace,
Color = Color3.fromRGB(255,255,255),
CFrame = CFrame.new(1,10,0),
Anchored = true,
CanCollide = true,
Size = Vector3.new(2,10,2),
Attributes = {
["IsTouched"] = false,
["DefaultSize"] = Vector3.one,
},
Touched = function(otherPart)
print(otherPart.Name .. " touched!")
end,
GetPropertyChangedSignal = {
args = {"Name"},
callback = function(object)
print("Name changed to "..object.Name)
end,
},
Children = {
Create("Part", {
Name = "Head",
Size = Vector3.new(5,5,5),
Anchored = true
})
}
})
ROBLOX Method:
- Download the module from Marketplace
- Place it on your desired path
Wally Method:
- Add
SmartCreate = "ashp116/smartcreate@^2.1.0"
to yourwally.toml
for your project - Run
wally install
Example Script:
local SmartCreate = require(PATH_TO_SMART_CREATE)
local Create, Edit = SmartCreate.Create, SmartCreate.Edit
local CoolPart= Create("Part", {
Name = "CoolPart",
Parent = workspace,
Color = Color3.fromRGB(255,255,255),
CFrame = CFrame.new(0,0,0),
Touched = function(otherPart)
print(otherPart.Name .. " touched!")
end,
GetPropertyChangedSignal = {
args = {"Name"},
callback = function(object)
print("Name changed to "..object.Name)
end,
},
Children = {
Create("Part", {
Name = "CoolPart2.0",
Size = Vector3.new(5,5,5),
Anchored = true
})
}
})
Edit(CoolPart, {
CFrame = CFrame.new(0,10,0)
})
Types
Properties:
[string] : any
,
Parent: Instance
,
Attributes: {[string] : string | boolean | number | UDim | UDim2 | BrickColor | Color3 | Vector2 | Vector3 | NumberSequence | ColorSequence | NumberRange | Rect}
,
Children: {Instance}
Methods
Create (ClassName: string, Properties: Properties) â Instance
Edit (Object: Instance, Properties: Properties) â Instance
CreateValueBase (Value: Any, Properties: Properties?) â ValueBase
1.0 - July 28, 2023
- Launch
- Bug Fixes
2.0 - July 30, 2023
- Added support for ValueBase creation from any data types
- Added support for Function properties of an Instance. Resolving
:
function of instances
FEEDBACK
Please reply to this post, it would help me a lot. You can comment on my work, or I need to fix any bugs, or even just want help. I will be updating the module.
Thanks for reading and hope this helped !!!
Gist
: SmartCreate.lua ¡ GitHub