Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

1 Random Thing?

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

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()

4 comments

0

What does that return do? What does it mean?

0

Im using this in a later loop, will your way still work?

0

Hm? Just look at what the randomPerson does and stuff. Should be self explanitory.

0

But what does return mean, I've never used it?

This discussion is preserved as it was. New answers, comments, and votes are closed.