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

Why does this anti repeat not work?

Asked by
Vrakos 109
10 years ago

I have 3 pads in the Workspace. I made this function to pick 3 random maps and display them on the boards.

The problem is that I don't want the same map to show up on any of the other boards as one board. I've tried a series of solutions, but none have worked.

Does anyone have a simple solution?

function PickRandomCubes()
Picked = {}
for Index,Board in pairs(Workspace.Vote:GetChildren()) do
print(Board.Name)
Maps = game.ServerStorage.CubeMapI:GetChildren()
Map = Maps[math.random(1,#Maps)]
for Index,A in pairs(Picked) do
if Map.Name == A.Name then
repeat Map = Maps[math.random(1,#Maps)] until Map.Name ~= A.Name
end
end
table.insert(Picked,Map)
Board.SurfaceGui.ImageLabel.Image = Map.Value
Board.SurfaceGui.MapName.Text = Map.Name
end
end

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago
function PickRandomCubes()
    local t={}
    local maps=game.ServerStorage.CubeMapI:GetChildren()
    for i,board in pairs(workspace.Vote:GetChildren())do
        local index=math.random(1,#maps)
        t[#t+1]=maps[index]
        maps[index]=nil
        local unpicked={}
        for _,v in next,maps do
            unpicked[#unpicked+1]=v
        end
        maps=unpicked
        board.SurfaceGui.ImageLabel.Image = Map.Value
        board.SurfaceGui.MapName.Text = Map.Name
    end
end

Each map is added to a list of maps to choose from. Each time a map is chosen, it is removed from the list.

Ad

Answer this question