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
|
  |
| 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
|
  |
| Joined: 13 Feb 2012 |
| Total Posts: 165 |
|
|
| 18 Nov 2016 12:13 PM |
| it won't write in separate lines |
|
|
| Report Abuse |
|
|
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 |
|
|