I am making a elevator game similar to the normal elevator and I am wondering the best way to randomize floors without repeats of the same floor here is the script.
local IntermissionTime = 10
local RoundTime = 15
local Time = game.ReplicatedStorage.Values.Time
local InRound = game.ReplicatedStorage.Values.InRound
local DoorTime = 2.5
InRound.Value = false
local maps = game.ReplicatedStorage.Maps
local telepart = workspace.Elevator.telepart
local wall = workspace.Elevator.Doors.wall
local NoTele = false
wait(2)
InRound.Changed:Connect(function()
if InRound.Value == true then
map = math.random(1,3)
print(map)
if map == 1 then
RoundTime = 15
mapclone = maps.TacoStand:Clone()
mapclone.Parent = workspace
elseif map == 2 then
RoundTime = 5
mapclone = maps.map_gaming:Clone()
mapclone.Parent = workspace
wall.CanCollide = true
NoTele = true
elseif map == 3 then
RoundTime = 15
mapclone = maps.TestMap3:Clone()
mapclone.Parent = workspace
elseif map == 4 then
RoundTime = 15
mapclone = maps.TestMap2:Clone()
mapclone.Parent = workspace
end
else
wall.CanCollide = true
if NoTele == false then
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character
char.HumanoidRootPart.CFrame = telepart.CFrame
end
end
wait(5)
mapclone:Destroy()
wall.CanCollide = false
NoTele = false
end
end)
local function timerfunction()
while wait() do
for i = IntermissionTime, 0, -1 do
wait(1)
Time.Value = i
end
print(“opendoor”)
InRound.Value = true
wait(DoorTime)
for i = RoundTime, 0, -1 do
wait(1)
Time.Value = i
end
print(“door close”)
InRound.Value = false
wait(DoorTime)
end
end
Track the last rooms and if the random number picked is similar then pick another number until it doesn’t match the last 10 rooms or any of the last rooms
Or you could the insert the number it into a table and remove it, once the function is called, this way the number doesn’t get repeated again. Also please consider formatting you code, so that it’s readable.
I inserted the number using a table named roomtable and made it insert the number into the table using table.insert(roomtable,map). Im sorry if this is an amateur question but what would I do after I have the number stored?
If it helps I can post a simplified version of what the script looks like so you can have a better understanding
map = math.random(1,3) --random number
table.insert(roomtable,map) --[[roomtable is a predefined table and I am adding the random number to the table–]]
no worries, but you would have to do something like
for your math.random you can say
local AvailableMaps = Maps:GetChildren()
local chosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
-- then you would say
if map == 1 then
table.remove(Maps,1)
Edit : I don’t think the last bit is right. I’m not good of a scripter myself