I have a few objects such as buildings and npcs that I create when my game starts, however, my current method is pretty clunky since I use tags and attributes which is sometimes a pain because if I forget to tag or add an attribute or make a typo it won’t work so I was wondering if there’s some other more efficient method I could use.
This is my current code that creates the interactable objects in my game
local function createInteractableObject(model)
local objectType = model:GetAttribute("ObjectType")
if objectTypes[objectType] then
local obj = Factory.create(objectTypes[objectType],model)
if obj.positions then
for _,position in pairs(obj.positions) do
self.octree:CreateNode(position, obj)
end
elseif obj.position then
self.octree:CreateNode(obj.position, obj)
end
end
end
for _,model in pairs(CollectionService:GetTagged("Interactable")) do
createInteractableObject(model)
end
function Factory.create(objectType,model,...)
if objectType == objectTypes.CustomizationStation then
return CustomizationStation.new(model)
end
if objectType == objectTypes.NPC then
return NPC.new(model)
end
if objectType == objectTypes.Building then
local buildingData = {
interiorModel = model.Interior,
exteriorModel = model.Exterior,
insidePart = model.Interior.Inside,
outsidePart = model.Exterior.Outside
}
return Building.new(buildingData)
end
end