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: Finding the closest player to a block

Previous Thread :: Next Thread 
Victoria0001 is not online. Victoria0001
Joined: 27 Jun 2010
Total Posts: 781
07 May 2014 04:24 PM
I'm trying to write a script to find the closest player to a block, and do something accordingly, but I don't know where to start.
Report Abuse
Darkhawkshane is not online. Darkhawkshane
Joined: 05 Jan 2013
Total Posts: 206
07 May 2014 04:26 PM
maybe do: (block)=(the stud number)(player)change
Report Abuse
xXxMoNkEyMaNxXx is not online. xXxMoNkEyMaNxXx
Joined: 03 Oct 2008
Total Posts: 3120
07 May 2014 04:27 PM
Do you mean closest to anywhere on the block? like if it was the baseplate, it woul measure how far away you are from the surface?
Report Abuse
Victoria0001 is not online. Victoria0001
Joined: 27 Jun 2010
Total Posts: 781
07 May 2014 04:34 PM
Nah, Im talking small scale, like literally a 1x1 block, and how far away all players are from it, then it gets the closest one and then the rest is up to me :P
Report Abuse
xXxMoNkEyMaNxXx is not online. xXxMoNkEyMaNxXx
Joined: 03 Oct 2008
Total Posts: 3120
07 May 2014 04:45 PM
Loop through the players, measure the distance to their torso with (Part.Position-Torso.Position).magnitude, and at the same time, see if it's less than the smallest distance so far. If it is, update the currently closest player variable and their distance.
Report Abuse
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
07 May 2014 04:57 PM
Anyone else notice the 45k views?
Report Abuse
Victoria0001 is not online. Victoria0001
Joined: 27 Jun 2010
Total Posts: 781
07 May 2014 05:11 PM
Yeah... I see that too.
Report Abuse
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
07 May 2014 06:01 PM
someone did that on my thread also :/
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
07 May 2014 06:08 PM
You would use magnitude.

table = {}

for i,v in pairs(game.Players:GetChildren()) do
while wait() do
local m = (v.Character.Torso.Position-workspace.Part.Position)
table.insert(table,m)
table.sort(table)
print(table[1])
end
end
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
07 May 2014 06:09 PM
table = {}

for i,v in pairs(game.Players:GetChildren()) do
while wait() do
local m = (v.Character.Torso.Position-workspace.Part.Position).magnitude
table.insert(table,m)
table.sort(table)
print(table[1])
end
end

Sorry, messed up.
Report Abuse
Victoria0001 is not online. Victoria0001
Joined: 27 Jun 2010
Total Posts: 781
08 May 2014 04:57 AM
Thanks for trying cooldude, but it's not working properly. It's printing the value of the nearest player's torso from the block I have it set to, and even then it only updates when I get closer. What I needed it to do was find the closest player (at all times, even after someone leaves or joins), and then I can do something only to that closest player.
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
08 May 2014 04:58 AM
68k views.
Report Abuse
Victoria0001 is not online. Victoria0001
Joined: 27 Jun 2010
Total Posts: 781
08 May 2014 05:00 AM
Lol.
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
08 May 2014 06:27 AM
table = {}

for i,v in pairs(game.Players:GetChildren()) do
while wait() do
local m = (v.Character.Torso.Position-workspace.Part.Position).magnitude
table.insert(table,m.." "..v.Name
table.sort(table)
print(table[1])
end
end

Try this.
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
08 May 2014 06:28 AM
table = {}

for i,v in pairs(game.Players:GetChildren()) do
while wait() do
local m = (v.Character.Torso.Position-workspace.Part.Position).magnitude
table.insert(table,m.." "..v.Name)
table.sort(table)
print(table[1])
end
end


Fixed an error.
Report Abuse
EcIiptic is not online. EcIiptic
Joined: 12 Aug 2009
Total Posts: 13737
08 May 2014 06:46 AM
@Cool

That simply doesn't work.

Due to the fact that there's a while loop in your for loop..


It would only go to one player and never to the next.

You could use a coroutine though.

for i, v in pairs(game.Players:GetChildren()) do
wrapp = coroutine.wrap(function()

end)
wrapp()
end

#Piano
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