Hello! Today, i’ll be showing you how to make an infinite obby generator(or an infinite anything generator). Without further ado, let’s get started!
Setting up
So, first, insert a folder inside workspace called: “Obbies”(or whatever you want for that matter). This will be to store the obbies and to find out the latest obby inside the bunch so we can place them.
Once you create the folder inside workspace, create a folder inside Replicated Storage called: “Obbies”. This is where we will store the available obbies that the script can get.
Building obbies
Now, you can build this however you want, BUT you must do 3 things like subribe and follow. Create a part called “Start”, this will be where the obby will start, make sure to center it(you can center it by copying the position of the platform and pasting it into the start part). After you create the start part, create a new part called “End”, this will be the end of the course. Make sure to center this one too! Once you finish building you obby, make the obby(all the parts including the start and end parts) into a model. Select all the obby’s parts and press ctrl + G. Then, move the obby into the “Obbies” folder inside replicated storage, then we could start to script!
Scripting
First, insert a script inside server script service and do this:
if u dont understand something, read whats on that line!
local Current = workspace.Obbies
local Obbies = game.ReplicatedStorage.Obbies:GetChildren() -- getting the current obbies
local StartingPos = CFrame.new(0,0,0) -- where the 1st part will be.
local MaxObbies = math.huge -- the obbies it generates(math.huge = inf)
local Rng = Random.new() -- rng for generating the obbies
local function Add(Obby) -- function for adding the obbies
local NewName = #Current:GetChildren() + 1
Obby.Name = string.format("%.f", NewName) -- names the obby
if Obby.Name == "1" then -- if this is the first obby generated
Obby:PivotTo(StartingPos) -- moves the obby into the starting pos
Obby.Parent = Current -- parents the obby so we can see it
else -- if it isn't the first obby generated
local LatestObby = Current:FindFirstChild(string.format("%.f", #Current:GetChildren())) -- gets the latest obby generated
if LatestObby then
Obby:PivotTo(LatestObby.End.CFrame) -- moves the obby to the latest obby's end part cframe
Obby.Parent = Current
end
end
end
for i = 1, MaxObbies, 1 do -- this will repeat the code between the for and the end based on the max obbies value
local RandomNum = Rng:NextInteger(1, #Obbies) -- gets a random integer(whole number, no decimals)
local Obby = Obbies[RandomNum]:Clone() -- gets an obby inside the obbies folder with the random number
if Obby then
Add(Obby) -- adds the obby
end
task.wait() -- not to crash the game
end
Final Result:
Outro
This is really really simple, you can add how many obbies you want. But keep in mind, this can really lag the game. It’s recommended you cap it to something instead of math.huge. Anyways, hope this helped you out! Peace!