#How to make a infinitly spawning backrooms?

33 messages · Page 1 of 1 (latest)

brittle whale
#

So i'm trying to make a backrooms game with render distance but i don't know how to make that

untold flame
#

you can watch a view videos about Dungeons Generation
basicly the same but with backrooms....rooms

brittle whale
#

I know

#

I made a basic script for that but the problem is

#

I need an render distance script

#

So that it only generates in the render distance

#

local parts = 20
local toSpawn = game.ReplicatedStorage:WaitForChild("ToSpawn")
local partsToSpawn = toSpawn:GetChildren()
local alreadyParts = workspace:WaitForChild("Parts")

for i = 1, parts do
local selectedPart = math.random(1, #partsToSpawn)
local chosenPart = toSpawn:WaitForChild("Part".. tostring(selectedPart))

local newPart = chosenPart:Clone()
local inGameParts = alreadyParts:GetChildren()
newPart.Name = tostring(#inGameParts + 1)
newPart.Parent = alreadyParts

newPart:SetPrimaryPartCFrame(alreadyParts:WaitForChild(#inGameParts).End.CFrame)

    i += 1

end

#

@untold flame

untold flame
#

i made a terrain generation script with that :

local loadpos = game.Players.LocalPlayer.Character.PrimaryPart.Position
local chunkX = math.floor(loadpos.X/chunksize)
local chunkZ = math.floor(loadpos.Z/chunksize)
    
local r = 3
for x=chunkX-r,chunkX+r do
    for z=chunkZ-r,chunkZ+r do
        gen(x,    z)
    end
end

i put each chunk in a group and saved the position of the chunk
when its to far away from the "loadpos" then it just gets deleted

brittle whale
#

how do i use the x and z in the function call

untold flame
#

its already in the function
its like for i=1,num do
i is how often it runned

brittle whale
#

bro

#

what function

untold flame
#

yea, you stilll need to to the chunk load function
mine generates terrain, not rooms
(a room is a chunk)

brittle whale
#

local loadpos = game.Players.LocalPlayer.Character.PrimaryPart.Position
local chunksize = 50
local chunkX = math.floor(loadpos.X/chunksize)
local chunkZ = math.floor(loadpos.Z/chunksize)

local r = 3
function gen(x, z)
local parts = 99999
local toSpawn = game.ReplicatedStorage:WaitForChild("ToSpawn")
local partsToSpawn = toSpawn:GetChildren()
local alreadyParts = workspace:WaitForChild("Parts")

for i = 1, parts do
    local selectedPart = math.random(1, #partsToSpawn)
    local chosenPart = toSpawn:WaitForChild("Part".. tostring(selectedPart))

    local newPart = chosenPart:Clone()
    local inGameParts = alreadyParts:GetChildren()
    newPart.Name = tostring(#inGameParts + 1)
    newPart.Parent = alreadyParts

    newPart:SetPrimaryPartCFrame(alreadyParts:WaitForChild(#inGameParts).End.CFrame)

    i += 1
    wait(0.1)
end

end

for x=chunkX-r,chunkX+r do
for z=chunkZ-r,chunkZ+r do
gen(x, z)
end
end

#

uhhhh

untold flame
#
function gen(x, z)
  RoomPos = vector2.new(x,z) * chunksize (aka roomsize)
end
brittle whale
#

where do i put this

untold flame
#

did you even write that code?

brittle whale
#

yes

#

bro

#

i never made a render distance script

#

im confused on what is going on

untold flame
#

dou just dont really do one you just generate whats near the player
is it a singleplayer game?

#

and btw that does newPart:SetPrimaryPartCFrame(alreadyParts:WaitForChild(#inGameParts).End.CFrame)

#

it loads the part at the last part in the folder?

brittle whale
#

???

dense craterBOT
#

studio** You are now Level 3! **studio

brittle whale
#

what does "dou" mean

untold flame
#

hers what ive got


local chunksize = 50



local alreadyParts = workspace:WaitForChild("Parts")

local r = 3
function gen(x, z)
    local name = "X "..x.." Z "..z
    if not alreadyParts:FindFirstChild(name) then
        local toSpawn = game.ReplicatedStorage:WaitForChild("ToSpawn")
        local partsToSpawn = toSpawn:GetChildren()
        
        local chosenPart = partsToSpawn[math.random(1, #partsToSpawn)]

        local newPart = chosenPart:Clone()
        newPart.Name = name
        newPart.Parent = alreadyParts

        newPart:SetPrimaryPartCFrame(CFrame.new(x*chunksize,0,z*chunksize))
    end
end



while task.wait(.5) do
  local loadpos = game.Players.LocalPlayer.Character.PrimaryPart.Position
  local chunkX = math.floor(loadpos.X/chunksize)
  local chunkZ = math.floor(loadpos.Z/chunksize)

  for x=chunkX-r,chunkX+r do
       for z=chunkZ-r,chunkZ+r do
          gen(x, z)
      end
  end
end
#

but i load them on client, you use math.random, i wouldnt recomend using it on a client map generation script
maybe use math.noise or something

brittle whale
#

tysm it works!

#

ill have to adjust and change some things but overall it works even with the code you provided