Anicor
|
  |
| Joined: 29 Nov 2008 |
| Total Posts: 161 |
|
|
| 14 Mar 2014 02:31 AM |
Ok so im trying to pick a random player from game.Players but for some reason its giving me an error(I have defined all of the variables here so thats not the problem) Here it is.
ranplayer = (math.random(1, #plyrs)) playerchosen = plyrs[ranplayer] h.Text = "The alien is: " .. playerchosen.Name"!"
Output: Workspace.MainScript:35: bad argument #2 to 'random' (interval is empty) |
|
|
| Report Abuse |
|
|
|
| 14 Mar 2014 02:36 AM |
plrs = game.Players:GetPlayers()
chosen = plrs[math.random(1,#plrs)] |
|
|
| Report Abuse |
|
|
Anicor
|
  |
| Joined: 29 Nov 2008 |
| Total Posts: 161 |
|
|
| 14 Mar 2014 02:41 AM |
| @kiwi nope exact same error. You just done the exact same thing i did, except you moved it to one line..... |
|
|
| Report Abuse |
|
|
|
| 14 Mar 2014 02:44 AM |
if #plyrs > 1 then ranplayer = (math.random(1, #plyrs)) playerchosen = plyrs[ranplayer] h.Text = "The alien is: " .. playerchosen.Name"!" else print'lolnope; must be atleast 2 plrs inside' end |
|
|
| Report Abuse |
|
|
Anicor
|
  |
| Joined: 29 Nov 2008 |
| Total Posts: 161 |
|
|
| 14 Mar 2014 02:47 AM |
ok im going to paste the whole script. like i said, ive already defined all of the variables but here.
h = Instance.new("Hint", Workspace) maps = game.Lighting.Maps:GetChildren() plyrs = game.Players:GetChildren()
while true do if game.Players.NumPlayers > 1 then for i = 10, 1, -1 do -- Make longer h.Text = "Intermission: " .. i .. " (Use this time to buy items or ask for help)" wait(1) end h.Text = "Choosing map" wait(3) ranmap = (math.random(1, #maps)) mapchosen = maps[ranmap] h.Text = "Map chosen: " .. mapchosen.Name wait(3) mapchosenclone = mapchosen:Clone() mapchosenclone.Parent = game.Workspace wait() h.Text = "Choosing alien" wait(3) playerchosen = plyrs[math.random(1, #plyrs)] h.Text = "The alien is: " .. playerchosen.Name"!" else h.Text = "There must be more than one player in the server for the game to start" end wait(1) end |
|
|
| Report Abuse |
|
|
|
| 14 Mar 2014 03:03 AM |
| = "The alien is: " .. playerchosen.Name.."!" -- you forgot the dots |
|
|
| Report Abuse |
|
|
Anicor
|
  |
| Joined: 29 Nov 2008 |
| Total Posts: 161 |
|
|
| 14 Mar 2014 03:07 AM |
| yes i see that i forgot to concatenate that, but that didnt fix the error.. still need help. same output |
|
|
| Report Abuse |
|
|
|
| 14 Mar 2014 03:12 AM |
while true do local plyrs = game.Players:GetChildren() -- this, put this here not outside if game.Players.NumPlayers > 1 then for i = 10, 1, -1 do -- Make longer h.Text = "Intermission: " .. i .. " (Use this time to buy items or ask for help)" wait(1) end h.Text = "Choosing map" wait(3) ranmap = (math.random(1, #maps)) mapchosen = maps[ranmap] h.Text = "Map chosen: " .. mapchosen.Name wait(3) mapchosenclone = mapchosen:Clone() mapchosenclone.Parent = game.Workspace wait() h.Text = "Choosing alien" wait(3) playerchosen = plyrs[math.random(1, #plyrs)] h.Text = "The alien is: " .. playerchosen.Name"!" else h.Text = "There must be more than one player in the server for the game to start" end wait(1) end
|
|
|
| Report Abuse |
|
|
Anicor
|
  |
| Joined: 29 Nov 2008 |
| Total Posts: 161 |
|
|
| 14 Mar 2014 03:17 AM |
| Yes, it works now. Im still trying to figure out why i needed that inside though..... Maybe because it needs to access a player? Thanks anyways. |
|
|
| Report Abuse |
|
|
|
| 14 Mar 2014 03:18 AM |
| i'd gladly explain why but you disable your party :/ |
|
|
| Report Abuse |
|
|
|
| 14 Mar 2014 03:58 AM |
| Maybe the plyrs table is empty |
|
|
| Report Abuse |
|
|