Heya, I’m making a Rogue-Like dungeon horror game, and I have the basics, I just don’t know how to adapt them to the game I’m specifically trying to make.
In the game, you go in an elevator and delve deep into a facility for as long as you can, each floor is randomly generated and you need to press buttons to advance to the next floor
I have the random generation script (kind of) but I don’t know how I’d go about unloading the map and generating a random new one each time the floor is completed.
Here’s the generation code:
--//Services
local pfs = game:GetService("PathfindingService")
--//Setup
local f = Instance.new("Folder", workspace)
f.Name = "CurrentGeneratedRooms"
for _,v in pairs(workspace.MapGrid:GetChildren()) do
v.Transparency = 1
end
for _,v in pairs(game.ReplicatedStorage.Rooms:GetChildren()) do
v.PrimaryPart = v.Floor
end
local rooms = game.ReplicatedStorage.Rooms:GetChildren()
local rotations = {0,90,180,270} -- directions the rooms can be rotated in
local roomGenerated = false
--//Functions
local function generateRooms()
f:ClearAllChildren()
for _,floor in pairs(workspace.MapGrid:GetChildren()) do
local chosenRoom = rooms[math.random(1, #rooms)]:Clone() --Pick random Room
chosenRoom:SetPrimaryPartCFrame(floor.CFrame * CFrame.Angles(0, math.rad(rotations[math.random(1,#rotations)]), 0))
chosenRoom.Parent = f
end
end
local function GiveLoadingScreen(player)
local gui = script.Loading:Clone()
gui.Parent = player.PlayerGui
end
--//Main
--Give Loading Screen
for _,player in pairs(game.Players:GetPlayers()) do
GiveLoadingScreen(player)
end
game.Players.PlayerAdded:Connect(function(player)
if roomGenerated == false then
GiveLoadingScreen(player)
end
end)
--Generate Rooms
local path = nil
repeat
generateRooms() --Generate rooms randomly
--Check if there is a path from start to end
path = pfs:CreatePath()
path:ComputeAsync(workspace.Start.Floor.Position, workspace.End.Floor.Position)
until
path.Status == Enum.PathStatus.Success
roomGenerated = true
for _,player in pairs(game.Players:GetPlayers()) do
if player.PlayerGui:FindFirstChild("Loading") then
player.PlayerGui.Loading:Destroy()
end
end
I have the rooms that can be generated stored in ReplicatedStorage, the generation script is in ServerScriptService and the generation template is located in the workspace.
I’d love any help on this, I’m really looking forward to developing this
Thank you in advance