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
 

Find Nearest Player

Previous Thread :: Next Thread 
Racer107 is not online. Racer107
Joined: 13 Feb 2012
Total Posts: 165
18 Nov 2016 12:11 PM
I am trying to make a ball chase the nearest player to the ball, I know how to get the distance from the ball to the players but how do I compare that distance with all the other players to decide which one is the closest? This is what I have: Playing = {} for i, v in pairs(game.Players:GetChildren())do table.insert(Playing, i, v) end local Ball = Instance.new("Part") ########## # ###### Ball.Parent = game.Workspace for i, Player in pairs(Playing)do local Distance = (Ball.Position - Player.Character.Torso.Position).magnitude end
Report Abuse
Racer107 is not online. Racer107
Joined: 13 Feb 2012
Total Posts: 165
18 Nov 2016 12:12 PM
Playing = {} for i, v in pairs(game.Players:GetChildren())do table.insert(Playing, i, v) end local Ball = Instance.new("Part") ########## # ###### Ball.Parent = game.Workspace for i, Player in pairs(Playing)do local Distance = (Ball.Position - Player.Character.Torso.Position).magnitude end
Report Abuse
Racer107 is not online. Racer107
Joined: 13 Feb 2012
Total Posts: 165
18 Nov 2016 12:13 PM
it won't write in separate lines
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
18 Nov 2016 12:48 PM
closest, target = nil
ball = script.Parent

while wait(1.5) do
closest = nil
for _,player in pairs(game.Players:GetChildren()) do
local char = player.Character
local torso = char.Torso
local distance = (torso.Position-ball.Position).magnitude
if distance < closest then
closest = distance
target = torso
-- adjust the bodymovers within the ball to follow the target
end
end)




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