Hello, So I am making the number reset back to one when you reach the specific “room” and more “rooms” after that.
My script code:
local room = require(script.Room)
local door = require(script.Room.Door)
local prevRoom = workspace.StarterRoom
local playerEnter = script.Room.PlayerEnter
local firstDoor = door.New(prevRoom, 1)
local generatedRooms = {prevRoom}
local Count = 1
if Count then
Count += 1
prevRoom = room.Generate(prevRoom, Count)
generatedRooms[Count] = prevRoom
end
playerEnter.Event:Connect(function(number, player)
if Count then
Count += 1
prevRoom = room.Generate(prevRoom, Count)
generatedRooms[Count] = prevRoom
end
end)
Room Module:
local TweenService = game:GetService("TweenService")
local door = require(script.Door)
local furniture = require(script.Furniture)
local item = require(script.Item)
local cdoor = require(script.CDoor)
local room = {}
room.info = require(script.RoomInfo)
room.lastTurnDirection = nil
room.random = Random.new()
room.cardrandom = Random.new()
local P50Room = game.ReplicatedStorage.Rooms.P50Room
local EndRoom = game.ReplicatedStorage.Rooms.EndRoom
local CRoom = game.ReplicatedStorage.Rooms.CRoom
function room.FlickerLight(lightPart)
local info = TweenInfo.new(0.2, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut, 1, false)
local flickOn = TweenService:Create(lightPart.Attachment.PointLight, info, {Brightness = 0.5})
local flickOff = TweenService:Create(lightPart.Attachment.PointLight, info, {Brightness = 0})
flickOff:Play()
flickOff.Completed:Wait()
lightPart.Material = Enum.Material.Glass
flickOn:Play()
flickOn.Completed:Wait()
lightPart.Material = Enum.Material.Neon
flickOff:Play()
flickOff.Completed:Wait()
lightPart.Material = Enum.Material.Glass
end
function room.Blackout(roomModel)
local light = roomModel.Build.Light
task.spawn(function()
room.FlickerLight(light)
end)
end
function room.GetRandom(prevRoom, p50room, endRoom, croom)
if p50room then
return P50Room
end
if endRoom then
return EndRoom
end
if croom then
return CRoom
end
local totalRarity = 0
for i, info in pairs(room.info) do
totalRarity += info.Rarity
end
local randomRarity = room.random:NextNumber(0, totalRarity)
local currentRarity = 0
local randomRoom = nil
for i, info in pairs(room.info) do
currentRarity += info.Rarity
if randomRarity <= currentRarity then
randomRoom = game.ReplicatedStorage.Rooms[i]
break
end
end
local direction = room.info[randomRoom.Name]["Direction"]
if (prevRoom.Name == randomRoom.Name)
or (direction and direction == room.lastTurnDirection)
then
return room.GetRandom(prevRoom)
else
if direction then
room.lastTurnDirection = direction
end
return randomRoom
end
end
function room.Generate(prevRoom, number)
local randomRoom = room.GetRandom(prevRoom, number == 51, number == 6, number > 6)
local newRoom = randomRoom:Clone()
newRoom.PrimaryPart = newRoom.Entrance
newRoom:PivotTo(prevRoom.Exit.CFrame)
local requiresKey = false
local locations = furniture.FurnishRoom(newRoom)
if locations and number < 6 then
if room.random:NextInteger(1, 300) == 300 then
local random = room.random:NextInteger(1, #locations)
local randomLocation = locations[random]
requiresKey = true
item.New(randomLocation, "Key")
end
if room.cardrandom:NextInteger(1, 5000) == 5000 then
local random = room.random:NextInteger(1, #locations)
local randomLocation = locations[random]
item.New(randomLocation, "Card")
end
end
if number < 6 then
local newDoor = door.New(newRoom, number, requiresKey)
elseif number >= 6 then
local newcDoor = cdoor.New(newRoom, number)
end
newRoom.Parent = workspace.GeneratedRooms
return newRoom
end
return room
Any help is appreciated, thanks.