Randomly generated sections

So in tower of hell, there are randomly generated sections from what looks like a folder of already made sections. I want to make this but in a corridor type thing. How would I do this?

What do you mean a corridor type thing?

Like in tower of hell, these randomly generated sections go up, I want mine to go fowards


Like this game

In that case its exactly the same but turned sideways? You need to know the length of each section you’ve chosen and place them in a line.

1 Like

Have a folder full of models that represent the different generatable segments. You can use :GetExtentsSize() to get the specific length of each individual segment when needed.

To choose a random segment, use the native ‘math.random()’ function. You could do something like this.

local segements = ReplicatedStorage.Segments:GetChildren()

function ChooseSegment(): Model
    return segments[math.random(1, #segments)]
end

function PositionSegment(lastSegment: Model, segment: Model)
    local sizeOffset = (model:GetExtentsSize().Z - lastSegment:GetExtentsSize.Z) / 2
    segment:PivotTo(lastSegment:GetPivot() * CFrame.new(0, 0, sizeOffset))
end

I wrote this quickly before going somewhere, so let me know if I did something wrong.

1 Like

As for the building part, ensure each section is the same length and size, and at the beginning and end of each section make a regular platform so when different sections are selected, the platforms connect no matter the order. I would place invisible walkthrough sections labelled “Section1, Section2, Section3,” etc. to reference placement in the randomized sections script.

For scripting, sounds like you’ll want a round base GUI timer that resets everyone at the end time, and to randomly select sections from a ReplicatedStorage folder to fill each Section1, Section2, etc.

Good luck!

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local segments = ReplicatedStorage.Segments:GetChildren()

local segment_tables = {}

local max = 100

local cooldown = 0.1

function ChooseSegment(): Model
	local random = segments[math.random(1, #segments)]
	table.insert(segment_tables, random)
	return random
end


function PositionSegment(lastSegment: Model, segment: Model)
	lastSegment = lastSegment or ChooseSegment()
	print(lastSegment)
	local sizeOffset = (lastSegment:GetExtentsSize().Z)
	segment:PivotTo(lastSegment:GetPivot() * CFrame.new(0, 0, sizeOffset))
	segment:Clone().Parent = workspace
end

local counter = 0

repeat PositionSegment(segment_tables[math.max(1, #segment_tables)], ChooseSegment()) task.wait(cooldown) counter+=1 until counter >= max

I used the structure of your script and fixed it a little bit and now it works

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.