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

Randomly choosing a player [closed]

Asked by 10 years ago

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.

0
It's Lua, not LUA. Lua is not an acronym. Thewsomeguy 448 — 10y

Locked by TheMyrco

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

Why was this question closed?

2 answers

Log in to vote
4
Answered by
TheMyrco 375 Moderation Voter
10 years ago

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

Ad
Log in to vote
1
Answered by 10 years ago

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.