generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Random player error

Previous Thread :: Next Thread 
Anicor is not online. 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
KiwiTronik is not online. KiwiTronik
Joined: 18 Feb 2010
Total Posts: 3221
14 Mar 2014 02:36 AM
plrs = game.Players:GetPlayers()

chosen = plrs[math.random(1,#plrs)]
Report Abuse
Anicor is not online. 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
meSmashsta is not online. meSmashsta
Joined: 31 Jan 2013
Total Posts: 1002
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 is not online. 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
meSmashsta is not online. meSmashsta
Joined: 31 Jan 2013
Total Posts: 1002
14 Mar 2014 03:03 AM
= "The alien is: " .. playerchosen.Name.."!" -- you forgot the dots
Report Abuse
Anicor is not online. 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
meSmashsta is not online. meSmashsta
Joined: 31 Jan 2013
Total Posts: 1002
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 is not online. 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
meSmashsta is not online. meSmashsta
Joined: 31 Jan 2013
Total Posts: 1002
14 Mar 2014 03:18 AM
i'd gladly explain why but you disable your party :/
Report Abuse
KiwiTronik is not online. KiwiTronik
Joined: 18 Feb 2010
Total Posts: 3221
14 Mar 2014 03:58 AM
Maybe the plyrs table is empty
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image