Hello devs,
Right now I am working on a “Rooms & Doors” inspired game. I’m trying to make a specific room (“PowerRoom”, as shown in the script below) generate between A-0001 and A-0020 only once, just like in Rooms and Doors.
local ServerStorage = game:GetService("ServerStorage")
local Events = ServerStorage.Events
local Values = ServerStorage.Values
local PreludeRooms = ServerStorage.PreludeRooms:GetChildren()
local PreludeRoomsAmount = 20
local RandomGeneration = Random.new()
Events.DoorOpen.Event:Connect(function()
local RoomClone = PreludeRooms[RandomGeneration:NextInteger(1, #PreludeRooms)]:Clone()
Values.RoomNumber.Value += 1
RoomClone:PivotTo(Values.CurrentRoom.Value.Exit.CFrame)
RoomClone.Parent = game.Workspace
RoomClone:FindFirstChild("Door").Main.Sound.PlaybackSpeed = RandomGeneration:NextNumber(0.5,1)
Values.CurrentRoom.Value = RoomClone
--Generate power room between the first and the last of the prelude rooms(A-0001 to A-0020)
if Values.RoomNumber.Value == math.random(1, PreludeRoomsAmount) then
local PowerRoom = PreludeRooms.PowerRoom:Clone()
Values.RoomNumber.Value += 1
PowerRoom:PivotTo(Values.CurrentRoom.Value.Exit.CFrame)
PowerRoom.Parent = game.Workspace
PowerRoom:FindFirstChild("Door").Main.Sound.PlaybackSpeed = RandomGeneration:NextNumber(0.5,1)
Values.CurrentRoom.Value = PowerRoom
end
--Turn lights off at game start
if Values.PreludeLights.Value == false then
local lights = RoomClone:GetChildren()
for _, light in pairs(lights) do
if light:IsA("Model") and light.Name == "light" then
light["Cube.001"]:FindFirstChild("Attachment"):FindFirstChild("PointLight").Brightness = 0.1
light["Cube.001"].Color = Color3.fromRGB(106,106,106)
end
end
else
-- Turn lights on when the switch is turned
local lights = RoomClone:GetChildren()
for _, light in pairs(lights) do
if light:IsA("Model") and light.Name == "light" then
light["Cube.001"]:FindFirstChild("Attachment"):FindFirstChild("PointLight").Brightness = 1
light["Cube.001"].Color = Color3.fromRGB(255, 255, 255)
end
end
end
--Room sign text formatting
if Values.RoomNumber.Value < 10 then
RoomClone:FindFirstChild("RoomSign").Text.SurfaceGui.RoomNumber.Text = "000"..Values.RoomNumber.Value
elseif Values.RoomNumber.Value < 100 then
RoomClone:FindFirstChild("RoomSign").Text.SurfaceGui.RoomNumber.Text = "00"..Values.RoomNumber.Value
else
RoomClone:FindFirstChild("RoomSign").Text.SurfaceGui.RoomNumber.Text = "0"..Values.RoomNumber.Value
end
end)
As you can see, I’ve tried math.random(min, max)
here, hoping it would work, as it generates values between the minimum and maximum values given in the brackets.