How do i can add a sequence like 123

what im saying its I want to add sequences of map spawn because what I used was math.random and it repeats the maps themselves here is a part of the same script

while true do  
wait(1)
local m = math.random(1,3)  --this part its where i want to change
local player = game.Players:GetPlayers()
for i = 1, #player do
msg = Instance.new("Message") 
msg.Parent = nil

if m == 1 then
msg.Parent = game.Workspace
msg.Text = "Choosing Map."
wait(0.8)
msg.Text = "Choosing Map.."
wait(0.8)
msg.Text = "Choosing Map..."
wait(0.8)
msg.Text = "The Code"  
wait(1)
msg.Text = "The map will change in 5 minutes."

game.Lighting.C0de:clone().Parent = game.Workspace	
game.Lighting.TimeOfDay= "14:30:00"

I mean basically I want to remove the math.random and that you put maps in numerical order and that it is repeated, that is, when there are no more maps, go back and put again from 1 to like 10 or idk any

You could put all of your maps into a table and create an index variable that will cycle through your maps.

local maps = {Map1Name, Map2Name, Map3Name}
local currentMap = nil
local index = 1

function nextMap()
    index += 1

    if index > #maps then
        index = 1
    end

    for i,map in pairs(maps) do
        if index == i then
            currentMap = map
        end
    end
end
local players = game:GetService("Players")
local lighting = game:GetService("Lighting")
local rs = game:GetService("ReplicatedStorage")
local mapFolder = rs:WaitForChild("Maps")
local maps = mapFolder:GetChildren() --place the maps (as single models) into a folder named "Maps" inside replicatedstorage
local mapsPlayed = 0

while task.wait() do 
	task.wait(1)
	local playerList = players:GetPlayers()
	local msg = Instance.new("Message")
	mapsPlayed += 1 --increments the maps played counter so that on the next loop the next map will be selected
	if mapsPlayed >= #maps then --check if maps played counter is greater than the number of maps then
		mapsPlayed = 1 --if it is then start from the first map again
	end
	if mapsPlayed == 1 then --if it is the first map
		msg.Parent = game.Workspace
		msg.Text = "Choosing Map."
		task.wait(0.5)
		msg.Text = "Choosing Map.."
		task.wait(0.5)
		msg.Text = "Choosing Map..."
		task.wait(0.5)
		msg.Text = "The Code"  
		task.wait(1)
		msg.Text = "The map will change in 5 minutes."

		local map = mapFolder:FindFirstChild("C0de"):Clone()
		map.Parent = workspace
		lighting.TimeOfDay= "14:30:00"
	end
end

I’ve added some comments in an attempt to guide you and give details on what I’ve added/changed etc.

Your solution technical works but the way you’re getting the current map is unnecessarily verbose.

Firstly, you can get the next index in a single line this way:

index = index % #maps + 1

This will cycle through all the indices in order.

Secondly, to get the current map you can index the map table directly:

currentMap = maps[index]

In full:

local maps = {Map1Name, Map2Name, Map3Name}
local currentMap = nil
local index = 1

function nextMap()
    index = index % #maps + 1
    currentMap = maps[index]
end
3 Likes