[Edit]: I find solution
Hello, I created a game on Roblox. The script itself works without errors, but the result is wrong—the rooms are generated incorrectly.
Can someone help me fix the script? I only need the room generation to work correctly.
ModuleScript:
local ServerStorage = game:GetService("ServerStorage")
function room.Generate(prevRoom)
local PossibleRooms = ServerStorage:WaitForChild("Rooms"):GetChildren()
local randomroom = PossibleRooms[room.random:NextInteger(1, #PossibleRooms)]
if #PossibleRooms == 0 then
return nil
end
if randomroom:WaitForChild("EnabledRoom") then
if randomroom:WaitForChild("EnabledRoom").Value == false then
local newRoom = randomroom:Clone()
wait()
newRoom.PrimaryPart = newRoom.Entrance
wait()
newRoom:PivotTo(prevRoom.Exit.CFrame)
wait()
newRoom.Parent = workspace.GeneratedRooms
wait()
randomroom:WaitForChild("EnabledRoom").Value = true
wait()
return newRoom
else
return randomroom
end
end
end
Script:
local room = require(script.RoomModuleScript)
local Players = game:GetService("Players")
local function generateNextRoom(player)
local prevRoom = workspace.Start
for i=1, 10 do
prevRoom = room.Generate(prevRoom)
task.wait()
end
end
generateNextRoom(Players.LocalPlayer)
When the game starts, the result is:
See? there are only 3 room, but where more?
