Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I stop the same map from being chosen twice?

I have made an effort to try and figure it out and I can't. I'm hoping someone will be able to help me else I'll be stuck on this problem for awhile.

Here is the code. Does anyone have any suggestions to stop it from choosing the same map twice in a row?

function chooseMap()					--Chooses Map (IN-PROGRESS)
	local mapChoice = math.random(1,3)
		if mapChoice == 1 then
			print("Map 1 got chosen!")
				local map = game.ServerStorage.Maps.Map1:clone()
				map.Parent = game.Workspace
				map:MoveTo(Vector3.new(100,100,100))
			--load map 1
		elseif mapChoice == 2 then
			print("Map 2 got chosen!")
				local map = game.ServerStorage.Maps.Map2:clone()
				map.Parent = game.Workspace
				map:MoveTo(Vector3.new(100,100,100))
			--load map 2
		elseif mapChoice == 3 then
			print("Map 3 got chosen!")
				local map = game.ServerStorage.Maps.Map3:clone()
				map.Parent = game.Workspace
				map:MoveTo(Vector3.new(100,100,100))
			--load map 3
	end	
end

1 answer

✓ Accepted answer

I tried to simplify the code along with your request. What I did is I added a condition that required the map to be different from the last map chosen, then setting that map to be the last map chosen.

local lastMap = 0
function ChooseMap()
	local mapChoice
	repeat mapChoice = math.random(1,#game.ServerStorage.Maps:GetChildren()) until mapChoice~=lastMap
	lastMap = mapChoice
	local map = game.ServerStorage.Maps["Map"..mapChoice]:Clone()
	-- Your loading code here.
end

2 comments

0

Thank you so much! This is exactly what I was looking for. Also, thanks for simplifying it, that's helpful and also just taught me something.

0

No problem!

This discussion is preserved as it was. New answers, comments, and votes are closed.