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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Random Teleport Script

Previous Thread :: Next Thread 
russellthesnake is not online. russellthesnake
Joined: 24 May 2011
Total Posts: 410
31 May 2014 04:06 PM
Why doesn't it work?

players = game.Players:GetChildren()

players[math.random(1,players.NumPlayers)]:MoveTo(Vector3.new(game.Workspace.Player1Teleport.Position))
players[math.random(1,players.NumPlayers)]:MoveTo(Vector3.new(game.Workspace.Player2Teleport.Position))






Thanks.
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
31 May 2014 04:09 PM
math.random(1, #players)
Report Abuse
Geomaster is not online. Geomaster
Joined: 05 Jul 2008
Total Posts: 1480
31 May 2014 04:11 PM
GetChildren returns a table, which do not have properties

Then you tried to index NumPlayers as a property of the 'players' table, which is a table and not the actual Player service itself.

Try this:

players = game.Players:GetPlayers() -- Use GetPlayers so it only searches for the player object

players[math.random(1, #players)]:MoveTo(workspace.Player1Teleport.Position)
players[math.random(1, #players)]:MoveTo(workspace.Player2Teleport.Position)
-- You can use #[table] to return the number of objects in that table
-- No reason to cast a position as a new Vector3, because it's already a V3 value
Report Abuse
russellthesnake is not online. russellthesnake
Joined: 24 May 2011
Total Posts: 410
31 May 2014 04:11 PM
Thanks for the help, but still doesn't work.
The error is "bad argument #2 to 'random' (interval is empty)".
Report Abuse
Geomaster is not online. Geomaster
Joined: 05 Jul 2008
Total Posts: 1480
31 May 2014 04:13 PM
Basically means there aren't any players. If you're using this in studio, make sure you code a check to make sure that #players > 0
Report Abuse
russellthesnake is not online. russellthesnake
Joined: 24 May 2011
Total Posts: 410
31 May 2014 04:31 PM
Doesn't work but thanks.
Do I add the if condition to the script?
Report Abuse
russellthesnake is not online. russellthesnake
Joined: 24 May 2011
Total Posts: 410
04 Jun 2014 05:13 PM
HELP PLIS
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