Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-mini-2024-07-18· OpenAIAi2 WildChat-4.8M (AI2)

create a roblox script that infinitely generate rooms, basically like a maze

  1. User

    create a roblox script that infinitely generate rooms, basically like a maze

  2. Assistant

    Creating an infinite maze generator in Roblox is quite a fun project! Here, I'll provide you with a basic script to get you started on generating rooms. This script will create a procedurally generated maze by generating rooms in random directions, infinitely.

    To keep it simple, let's assume each room is a simple Part (block), and when a room is created, a new room may be created in one of the available directions (up, down, left, right).

    Basic Infinite Room Generation Script

    1. Create a Roblox Place and open the script editor.
    2. Insert a Script into ServerScriptService or directly into the Workspace.
    3. Copy and paste the following code:
    -- Variables for room size and direction
    local roomSize = 20
    local directions = {
        Vector3.new(0, 0, roomSize),     -- Up
        Vector3.new(0, 0, -roomSize),    -- Down
        Vector3.new(roomSize, 0, 0),     -- Right
        Vector3.new(-roomSize, 0, 0)     -- Left
    }
    
    -- Table to track generated rooms
    local generatedRooms = {}
    
    -- Function to generate a room
    local function createRoom(position)
        local room = Instance.new("Part")
        room.Size = Vector3.new(roomSize, 1, roomSize)
        room.Position = position
        room.Anchored = true
        room.Parent = game.Workspace
    
        -- Store the room's position
        table.insert(generatedRooms, position)
    
        return room
    end
    
    -- Function to generate a maze
    local function generateMaze(startPosition)
        local currentPosition = startPosition
        createRoom(currentPosition)
    
        while true do
            -- Randomly pick a direction to create a new room
            local directionIndex = math.random(1, #directions)
            local newDirection = directions[directionIndex]
            currentPosition = currentPosition + newDirection
    
            -- Check if the room already exists
            local exists = false
            for _, pos in pairs(generatedRooms) do
                if pos == currentPosition then
                    exists = true
                    break
                end
            end
    
            -- If the room does not exist, create it
            if not exists then
                createRoom(currentPosition)
            end
    
            wait(0.5) -- Control the speed of room generation
        end
    end
    
    -- Start generating the maze
    generateMaze(Vector3.new(0, 0, 0))
    

    Explanation of the Code:

    1. Room Size: The size of each room is defined by the roomSize variable.
    2. Directions: The directions in which new rooms can spawn are defined as vectors.
    3. Generated Rooms: An array to track already generated room positions to ensure no duplicates.
    4. createRoom: A function to create a room at a given position and store its position in generatedRooms.
    5. generateMaze: Continuously generates rooms by picking a random direction and creating a new room if it hasn't been generated before.
    6. Infinite Loop: The loop in the generateMaze function continues indefinitely, generating new rooms until the script is stopped.

    How to Use:

    • Paste the script into your Roblox Place's server script.
    • Press Play to see the rooms being generated around the starting position.

    Note:

    1. This is a basic implementation. You can add more features like door transitions between rooms, different room shapes, or enhancements for the maze's complexity.
    2. Make sure that the Part does not collide with other objects in your game to avoid unexpected behavior.
    3. The performance may degrade with too many parts being generated; consider optimizing or limiting the number of rooms if necessary.

    Happy scripting, and enjoy building your infinite maze in Roblox!