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 » Scripters
Home Search
 

Re: Magnitude for every person in the server

Previous Thread :: Next Thread 
DoctorHelix is not online. DoctorHelix
Joined: 05 May 2015
Total Posts: 303
12 Jul 2015 10:55 PM
if I want a part that checks the magnitude of every person in the server.

Should I use for i,v in pairs()

or

game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]?

I think the second choice is better because when I tried using for i,v in pairs the script broke when someone leaves the server.
Report Abuse
iiEssence is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
12 Jul 2015 10:58 PM
for i,v in pairs(game.Players:GetChildren())


I don't need a siggy
Report Abuse
cooldude999921 is not online. cooldude999921
Joined: 13 Aug 2011
Total Posts: 3702
12 Jul 2015 11:06 PM
Yeah what he said

The second one chooses a random player from players
Report Abuse
RegularTetragon is not online. RegularTetragon
Joined: 10 Oct 2009
Total Posts: 3085
12 Jul 2015 11:06 PM
This checks if the player is still there, if the player has a character, and if the character has a torso. Something important to notice is the order in which they are checked, because if one fails then because there is an and requirement the if statement fails without ever checking the next two which could be erroneous, because if player is nil then there's no way you could even check its non-existent character, the torso in such a case would be totally out of the question. You might need to check the case of character, it's been about two weeks since I've been in town and as a direct consequence my roblox lua is a bit rusty.


for _,player in pairs (game.Players:GetChildren ()) do
if (player and player.character and player.character.Torso) then
magnitude = (part.position-player.character.Torso.position).magnitude
end
end
Report Abuse
DoctorHelix is not online. DoctorHelix
Joined: 05 May 2015
Total Posts: 303
13 Jul 2015 12:12 PM
Okay, but wouldn't for i,v in pairs() go in order?

so it'd go from

Player[1], then player[2], then player[3] and so on. And wouldn't it stop on the last player? or does it go back to player 1?

Because over night I was thinking maybe I should just do a for i loop checking how close every player is each second.
Report Abuse
lolb3 is not online. lolb3
Joined: 16 Jan 2010
Total Posts: 2268
13 Jul 2015 12:21 PM
while true do
in pairs loop
end
will end at the last player then restart
wait
end
Report Abuse
AstroCode is not online. AstroCode
Joined: 09 Oct 2009
Total Posts: 1122
13 Jul 2015 12:24 PM
while wait() do
for i, v in pairs(game.Players:GetPlayers()) do
if v.Character then
-- do your magnitude stuff
end
end
end
Report Abuse
DoctorHelix is not online. DoctorHelix
Joined: 05 May 2015
Total Posts: 303
13 Jul 2015 05:38 PM
Guys, I did:

if v.Character and if v then, etc. But it still breaks when they leave, why?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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