Script that Turns Parts into Buildings

Hey DevForum! I was going through 2019 Cool Creations when I saw GregTame’s post on making a block into a building with scripts only. His example:

To:

How would you go about writing a script to make parts into buildings?
All I could think of was having a loop go through a folder of parts.

Thanks,
-Cap

1 Like

What specifically are you asking about? If you’re asking about how to iterate through all the parts, yeah you’d probably just put them in a folder.

If you’re asking about how to make it yourself, I suspect he has some prefab build (3 categories I guess, roof, middle, ground floor), then rotates and sizes them to fit the parts.

2 Likes

Sorry if I wasn’t clear.

I am asking how you would make the script that transforms a part based an size and shape into a building.

Hi buddy :)! I can see depth in the building’s structures so I honestly couldn’t tell you. Though, with the right textures provided, a low-poly building, and some UV wrapping, it could be done easily. Hope you figure it out.

1 Like

Howdy!

So this was accomplished fairly simply by placing tiles on the front face of the building block, and having it pick specific tiles for specific parts of the building.

First I define where the bottom corner tile would go

BaseTileCF = Base.CFrame*CFrame.new(Base.Size.x/2,Base.Size.y/2-TileSize/2,Base.Size.z*2)

then place tiles according the floor, and column

Floors,Columns  = Base.Size.y/TileSize,Base.Size.x/TileSize --I'm assuming you rounded the block to the nearest tilesize incriment earlier
local MasterTile = GetRandomTile() -- this function gets you a random tile, I'm going to assume that you know how to get a random item from a table
for Floor=1,Floors do
    for Column=1,Columns do
    TileCF = BaseTileCF*CFrame.new((Column-1)*TileSize,(Floor-1)*TileSize,0)
    local Tile = MasterTile:Clone()
    Tile.CFrame = TileCF
    Tile.Parent = workspace -- this can be changed to however you want the parenting to work out
    end
end

if you want to get very fancy, you can do

if Floor == 1 then
   Tile =  GetRandomFirstFloorTile()--Again, I'm assuming you know how to get a random item from a specific table
else
   Tile = MasterTile:Clone()
end

How you build the tiles is up to you, i made mine out of unions.

the roofs were just some code that made a roof shape on top given dimensions

5 Likes

Thanks for the detailed explination!

This answered all of my questions.

1 Like

no problem, if you have any other questions on it, just post them here or DM me

1 Like