Hi. I'm still learning LUA.. and i was interested in how would i make a script that would randomly choose a user who is playing to be something? Like the stalker,killer etc.
✓ ANSWER ACCEPTED
Randomly choosing a player
2 answers
✓ Accepted answer
(Continuation after owen)
And to pick somebody that hasn't already been picked for something, do something similiar to this:
local Plrs = game.Players:GetPlayers() -- Add all players to Plrs table
local killer = Plrs[math.random(1,#Players)] -- Get a player, this player is defined under Plr1
local sherif1, sherif2;
repeat
sherif1, sherif2 = Plrs[math.random(1,#Players)], Plrs[math.random(1,#Players)]
until sherif 1 ~= killer and sherif2 ~= killer and sherif1 ~= sherif2
And, yes, you can also use for loops when using a table with multiple already picked people.
This is a very simple question, here is example code:
local Plrs = game.Players:GetPlayers() -- Add all players to Plrs table
Plr1 = Plrs[math.random(1,#Players)] -- Get a player, this player is defined under Plr1
Here is the ROBLOX wiki documentation.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
It's Lua, not LUA. Lua is not an acronym.