im trying to make a doors-type game with GnomeCodes doors tutorial videos. I have gotten to the 3rd video but have noticed he never shows how to make a certain room generate at say room 50 for example. i have 100 rooms generating at the moment and i want certain rooms to not be random and have a specific room spawn. how can i do that?
Check rooms amount by
#Path:GetChildren()
-- It will give you length of a table (GetChildren() gives you a table)
-- Using # before table giving you length of a table
Then lets say if its 50, you can create special room
(If you didnāt know, # works only with arrays (Where its like [1], [2], and not [āSomethingā], [āIdkā], it will just ignore these)
does it matter where in the script i put it?
this is it
local room = {}
room.info = require(script.RoomInfo)
room.lastTurnDirection = nil
room.random = Random.new()
function room.GetRandom(prevRoom)
local totalWeight = 0
for i, info in pairs(room.info) do
totalWeight += info.Weight
end
local randomWeight = room.random:NextNumber(0, totalWeight)
local currentWeight = 0
local randomRoom = nil
for i, info in pairs(room.info) do
currentWeight += info.Weight
if randomWeight <= currentWeight then
randomRoom = workspace.Rooms[i]
break
end
end
local direction = room.info[randomRoom.Name]["Direction"]
local hasStairs = room.info[randomRoom.Name]["Stairs"]
local prevHadStairs = room.info[prevRoom.Name]["Stairs"]
if (prevRoom.Name == randomRoom.name)
or (direction and direction == room.lastTurnDirection)
or (hasStairs and prevHadStairs)
then
return room.GetRandom(prevRoom)
else
if direction then
room.lastTurnDirection = direction
end
return randomRoom
end
end
function room.Generate(prevRoom)
local randomRoom = room.GetRandom(prevRoom)
local newRoom = randomRoom:Clone()
newRoom.PrimaryPart = newRoom.Entrance
newRoom:PivotTo(prevRoom.Exit.CFrame)
newRoom.Entrance.Transparency = 1
newRoom.Exit.Transparency = 1
newRoom.Parent = workspace.GeneratedRooms
return newRoom
end
return room
Put it before generating new room,
check amount of created rooms,
if it = to lets say 50,
you force select room
Where you select room, check rooms amount, if its at your wanted amount, force select any room