Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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?

01function chooseMap()                    --Chooses Map (IN-PROGRESS)
02    local mapChoice = math.random(1,3)
03        if mapChoice == 1 then
04            print("Map 1 got chosen!")
05                local map = game.ServerStorage.Maps.Map1:clone()
06                map.Parent = game.Workspace
07                map:MoveTo(Vector3.new(100,100,100))
08            --load map 1
09        elseif mapChoice == 2 then
10            print("Map 2 got chosen!")
11                local map = game.ServerStorage.Maps.Map2:clone()
12                map.Parent = game.Workspace
13                map:MoveTo(Vector3.new(100,100,100))
14            --load map 2
15        elseif mapChoice == 3 then
View all 22 lines...

1 answer

Log in to vote
4
Answered by
Legojoker 345 Moderation Voter
9 years ago

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.

1local lastMap = 0
2function ChooseMap()
3    local mapChoice
4    repeat mapChoice = math.random(1,#game.ServerStorage.Maps:GetChildren()) until mapChoice~=lastMap
5    lastMap = mapChoice
6    local map = game.ServerStorage.Maps["Map"..mapChoice]:Clone()
7    -- Your loading code here.
8end
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. megamario640 50 — 9y
0
No problem! Legojoker 345 — 9y
Ad

Answer this question