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

Make sure a random object isn't picked twice?

Asked by 8 years ago

so I'm trying to make an effect like this for my minigames game.

And I have come up with an idea, choose a amount of random maps, place their names into a table and then put the table contents into different surfacegui text labels (the place in the video is 2 years old and abandoned, it uses decals) and then use a for loop to go through them and have it slow down and stop on one of the maps, then pick that one as the map

`   for i2 = 1, #maps:GetChildren() do

        repeat
            wait()
            randmap = maps:GetChildren()[math.random(1,#maps:GetChildren())].Name
        until randmap ~= lastchosenmap

        print("Hello!")
        if not chosenmaps[randmap] then
            print("HI!")
            chosenmaps[randmap] = true
            lastchosenmap = randmap
        end
    end
`

I put all the maps inside a table called chosenmap and set it to true (so it's easier to check if they're already in the table), what I want to do is make sure that the random map that is going to be put into the table hasn't already been picked.

Answer this question