Convert number to model in folder

Hello. I’m trying to make a random room generator. I want to make a starting room randomly generate, so I did this:

local rooms = game.Workspace.MapParts:GetChildren()
local startingroomnum = math.random(1, #rooms)
local startingroom = 

I’m looking for a way to convert that number into an item in the folder ‘mapparts’ instead of writing

if startingroomnum == 1 then
startingroom = mappart1
end

and so on. Thanks to anyone who can help!

That is simple, you already have the array of rooms, so all you need is to index the startingroomnum with the rooms array to get the model of the room:

local rooms = game.Workspace.MapParts:GetChildren()
local startingroomnum = math.random(1, #rooms)
local startingroom = rooms[startingroomnum]
1 Like

Thanks. This worked.

image

The script is in this folder too. Is there any way to exclude that, because as you can see in the image, the script has also been listed.

—Edit: Nvm I can just move the script.

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