User:NXTBoy/Scripts/"new" operator
From Legacy Roblox Wiki
< User:NXTBoy | Scripts
_G.new = function(typeName) return function(properties) pcall(function local i = Instance.new(typeName) if type(properties) == "table" then for property, value in pairs(properties) do if type(property) == "number" then value.Parent = i else i[property] = value end end end return i end end
Usage as follows:
local new = _G.new local m = new "Model" { Name = "Test", Parent = workspace, new "Part" { Name = "My Part", BrickColor = BrickColor.Red(), Size = Vector3.new(2, 2, 2) } } local p = new "Part"() p.Parent = m