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: Find the character that is closest to the NPC

Previous Thread :: Next Thread 
DerpyMerpKing is not online. DerpyMerpKing
Joined: 05 Feb 2011
Total Posts: 2553
29 Jul 2015 03:01 PM
I want to do this so I can use BodyGyros to rotate the NPC's head towards the player nearest to it.
if siggy == false then print"nooo :(" end
Report Abuse
DerpyMerpKing is not online. DerpyMerpKing
Joined: 05 Feb 2011
Total Posts: 2553
29 Jul 2015 05:23 PM
b
if siggy == false then print"nooo :(" end
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
29 Jul 2015 05:35 PM
lets start by getting closest person.

AI = script.Parent
tor = AI.Torso
bodygyro = AI.Head.BodyGyro
local folder = Instance.new("Folder", game.Workspace)
folder.Name = "Folder";

while wait(1) do
local tab = {}
for i,v in pairs(game.Players:GetPlayers()) do
wait()
table.insert(tab, (v.Character.Torso.Position - tor.Position).magnitude)
end
table.sort(tab);
local closest = tab[1]--least to most, 1st will be least, therefore closest
local closestPLR
for i,v in pairs(game.Players:GetPlayers()) do
wait()
if (v.Character.Torso.Position - tor.Position).magnitude == closest then
closestPLR = v;
bodygyro.cframe = CFrame.new(AI.Head.Position, closestPlr.Head.Position)
end
end
end

tell me if that works
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
29 Jul 2015 05:41 PM
@OP

put a danm space between what you say and your siggy. ffs


"Talk is cheap. Show me the code." - Linus Torvalds
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
29 Jul 2015 06:07 PM
Jerk^ dont listen to him hes mean
Report Abuse
DerpyMerpKing is not online. DerpyMerpKing
Joined: 05 Feb 2011
Total Posts: 2553
29 Jul 2015 08:57 PM
I dont like having to press enter every time...
like this

if siggy == false then print"nooo :(" 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