I need my script to not repeat a minigame 3x in a row

I want the maps in my minigames place to not repeat at all, but the minigames repeat three times.



while true do
	workspace["Elevator Music"]:Play()
	for i = 1,25 do
		s.Value = "Intermission ("..25-i ..")"
		wait(1)
	end
	s.Value = "Choosing map..."
	wait(1)
	local chosen = math.random(1,5)
	local nextGame
	if chosen == 1 then
		nextGame = game.ReplicatedStorage.Obbies["Volcanic Valley"]
		workspace.Sounds["Cartoon - On  On (feat. Daniel Levi) NCS "]:Play()
		s.Value = "Chosen map: 'Sandstone Ruins', Creator: Sufganiyot, Created: 2021, Difficulty: Medium"
	end
	if chosen == 2 then
		workspace.Sounds["Jim Yosef - Unicorn"]:Play()
		nextGame = game.ReplicatedStorage.Obbies["FutureBLOX Tech HQ"]
		s.Value = "Chosen map: 'FutureBLOX Tech HQ', Creator: Sufganiyot, Created: 2021, Difficulty: Hard"
	end
	if chosen == 3 then
		workspace.Sounds["Waysons - Eternal Minds"]:Play()
		s.Value = "Chosen map: 'Lava Canyon', Creator: Sufganiyot, Created: 2021, Difficulty: Extreme"
		nextGame = game.ReplicatedStorage.Obbies["Lava Canyon"]
	end
	if chosen == 4 then
		workspace.Sounds["Kovan & Electro-Light - Skyline"]:Play()
		nextGame = game.ReplicatedStorage.Obbies["Winter Wonderland"]
		s.Value = "Chosen map: 'Winter Wonderland', Creator: Sufganiyot, Created: 2021, Difficulty: Medium"
	end
	if chosen == 5 then
		workspace.Sounds["My Heart by Different Heaven"]:Play()
		nextGame = game.ReplicatedStorage.Obbies["Sandstone Ruins"]
		s.Value = "Chosen map: 'Sandstone Ruins', Creator: Sufganiyot, Created: 2021, Difficulty: Easy"
	end
	wait(2)
	clone = nextGame:Clone()
	clone.Parent = game.Workspace
	s.Value = "Teleporting players..."
	workspace["Elevator Music"]:Pause()
	wait(1)
	p = game.Players:GetChildren()
	for i = 1, #p do
		p[i].Character:MoveTo(workspace.tp1.Position)
		p[i].Team = game.Teams.Playing
		p[i].Character.Head.Anchored = true	
	end
	s.Value = "3!"
	wait(1)
	s.Value = "2!"
	wait(1)
	s.Value = "1!"
	wait(1)
	s.Value = "GO!"
	for i = 1, #p do
		p[i].Character.Head.Anchored = false
	end
	wait(1)
	
	local gametime = 60
	while  gametime > 0 do
		s.Value = gametime
		wait(1)
		local team = game.Teams.Playing:GetPlayers()
		if #team == 0 then
			gametime = 0
		end
		gametime = gametime - 1
	end
	
	s.Value = "Round over!"
	wait(1)
	for i = 1, #p do
		p[i].Character:MoveTo(workspace.goher.Position)
		p[i].Team = game.Teams.Spectators
		p[i].Character.Humanoid.Health = 100

		end
	clone:Destroy()
	nextGame = -1
	workspace.Sounds["Cartoon - On  On (feat. Daniel Levi) NCS "]:Pause()
	workspace.Sounds["Waysons - Eternal Minds"]:Pause()
	workspace.Sounds["Jim Yosef - Unicorn"]:Pause()
	workspace.Sounds["Kovan & Electro-Light - Skyline"]:Pause()
	workspace.Sounds["My Heart by Different Heaven"]:Pause()
end

You can add a variable that records the number of last mini-game done. Then throw an if statement into there saying something like “if chosen ~= NumberOfLastGame then”. If the number turns out to be the same, have it repeat until a different number is chosen.

1 Like

You can make something like this when choosing the minigame.
This is for not having the same minigame twice in a row

repeat
wait()
LastMinigame = Minigame
Minigame = math.random(1,5)
until LastMinigame ~= Minigame

And this is for not having the same minigame three times in a row. The difference is just adding another variable

repeat
wait()
LastLastMinigame = LastMinigame
LastMinigame = Minigame
Minigame = math.random(1,5)
until LastMinigame ~= Minigame and LastLastMinigame ~= Minigame

3 Likes

thanks it worked :+1: !!!