So, I'm trying to make a procedural generation system similar to games like SCP: Secret Laboratory. The room templates are models that all have a PrimaryPart named "Floor" in them. However, only the Floor copies onto the map when generated, but not the model. Any ideas?
--Variables local prefabs = game.ServerStorage.Prefabs local rooms = 9 local width = 3 local length = 3 local x = 0 local y = 1 local z = 0 local rows = 0 local w = 0 local l = 0 local chance = 0 math.randomseed(tick()) function drawRoom(room, xp, yp, zp, location, num) if num == "" then local newRoom = prefabs[room]:Clone() newRoom.Parent = location newRoom.Floor.CFrame = CFrame.new(xp, yp, zp) else local newRoom = prefabs[room]:Clone() newRoom.Parent = location newRoom.Floor.CFrame = CFrame.new(xp, yp, zp) end end --Generation for i = 1, width, 1 do for i = 1, length, 1 do wait() if w == width then w = 0 rows = rows + 1 x = x - 50 z = z - 50 print(l) --For testing purposes l = l + 1 else chance = math.random(0, 3) if chance < 0.15 then drawRoom("EndRoom", x, y, z, workspace.World, chance) elseif chance < 1 and chance > 0.5 then drawRoom("Hall", x, y, z, workspace.World, chance) elseif chance > 1 then drawRoom("4Way", x, y, z, workspace.World, "") end w = w + 1 z = z + 50 end end end
When moving a model with a PrimaryPart using regular CFrame only moves one part. When working with primary parts you need to use MoveTo or SetPrimaryPartCFrame. Most people will recommend using SetPrimaryPartCFrame because MoveTo collides with other parts.
Ex.
local x = 100 local y = 0 local z = 10 game.Workspace.Model.PrimaryPart = game.Workspace.Model.Part1 game.Workspace.Model:SetPrimaryPartCFrame(CFrame.new(x, y, z))