Skip to content

Instantly share code, notes, and snippets.

@Adidea
Created June 21, 2015 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adidea/5fc561e72f989abb2555 to your computer and use it in GitHub Desktop.
Save Adidea/5fc561e72f989abb2555 to your computer and use it in GitHub Desktop.
Create instances from a table against a list of prioritized properties
function create(name, parent)
local priority = {
"BottomSurface",
"TopSurface",
"LeftSurface",
"RightSurface",
"FrontSurface",
"BackSurface",
"Shape",
"FormFactor",
"Anchored",
"Size",
"CFrame",
"Position",
}
local parentLast = nil
local function setPriorities(new, props)
for i,v in pairs(priority) do
if props[v] then
new[v] = props[v]
props[v] = nil
end
end
parentLast = props["Parent"]
props["Parent"] = nil
end
return function(props)
local new = Instance.new(name)
setPriorities(new, props)
for i, v in next, props do
if type(i) == 'number' then
v.Parent = new
else
new[i] = v
end
end
new.Parent = parentLast or parent
return new
end
end
local test = create("Part") {
TopSurface = "Smooth",
BottomSurface = "Smooth",
Anchored = true,
Shape = "Ball",
Position = Vector3.new(0, 10, 0),
Name = "Test",
Parent = workspace
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment