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

1 Random Thing?

Asked by
Tor6 0
10 years ago

When you script to pick a random thing or in my case a person, how would you do it so that it only picks 1 person and not 5 people? Here is my example.

function findperson()
player = game.Players:GetPlayers()
person = player[math.random(1, #player)]
end

Does the # 1 mean that it picks 1 person? Cause for some reason, it picks random numbers of people like 2 or 3 or 1 or 4?

1 answer

Log in to vote
0
Answered by 10 years ago

Uhm, it already does pick one person. I believe you were using 'player' variable. Also you should use return instead of using global variables.

function findperson()
    local players = game.Players:GetPlayers()
    local person = players[math.random(#players)]
    return person
end

randomPerson = findperson()
0
What does that return do? What does it mean? Tor6 0 — 10y
0
Im using this in a later loop, will your way still work? Tor6 0 — 10y
0
Hm? Just look at what the randomPerson does and stuff. Should be self explanitory. ZarsBranchkin 885 — 10y
0
But what does return mean, I've never used it? Tor6 0 — 10y
Ad

Answer this question