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

how can I make math.random select more than 1 random thing? [closed]

Asked by 8 years ago

I need to know how to do this because in my new game project math.random only selects 1 player to be the criminal.

here is an example of what I have to make it select 1 person.

criminals = people[math.random(1, #people)]

Locked by MessorAdmin, User#5978, and HungryJaffer

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 8 years ago

The reason is for that theres only 1 player selected is because your using

math.random(1,  #people)

The '1' makes it only select one player.

I suggest using a table.

Much easyer to use. Example code :

criminals = {}

for i = 1, math.random(1, 5), 1 do

    while wait() do
        local NC = people[math.random(1, #people)]
        for _,plr in next,criminals do
            if plr ~= NC then
                table.insert(criminals, NC)
                break -- Stop the while loop
            end
        end
    end

end

So now what you can do is much MUCH more simple,

Example

for _,plr in next,criminals do
    local Character = workspace:WaitForChild(plr.Name)
    local Human = Character:WaitForChild("Humanoid")
    Humanoid.Died:connect(function()
        print(Character.Name..", died")
    end)
end

0
1. "The '1' makes it only select 1 player" is false; the '1' just says "return a random number with value at least 1". 2. Your inner loop doesn't work: it will always add the criminal, regardless of whether they're in the table of criminals or not. 3. I recommend using "#people/2", not "math.random(1,5)" - what if there are only 4 players, for instance? chess123mate 5873 — 8y
Ad