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: AI follow player

Previous Thread :: Next Thread 
StickMasterNinja2 is not online. StickMasterNinja2
Joined: 18 May 2013
Total Posts: 1170
24 Jan 2015 04:04 PM
function FindNearestTorso()
local nearest
for _,b in pairs (Players:GetChildren()) do
if nearest == nil then
nearest = b.Character:FindFirstChild("Torso")
else
if b.Character:FindFirstChild("Torso") ~= nil then
if(b.Character.Torso.Position - script.Parent.Torso.Position).magnitude < (nearest.Position - script.Parent.Torso.Position).magnitude then
nearest = b
end
end
end
end
end

while true do
wait(1)
local target = FindNearestTorso()
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end
end

I seen in the SA, that "Players" is an unknown global.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
24 Jan 2015 04:10 PM
Well then define it so that it doesn't have a problem.
Report Abuse
StickMasterNinja2 is not online. StickMasterNinja2
Joined: 18 May 2013
Total Posts: 1170
24 Jan 2015 04:21 PM
Please, I need a solution of this error.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
24 Jan 2015 04:23 PM
Just define it somewhere.

http://wiki.roblox.com/index.php?title=Variables
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
24 Jan 2015 04:31 PM
I made your torso finding function better
codepad
/20fw5VXr


Now it has an optional argument for npc characters and returns all the torsos in order of closeness
Report Abuse
StickMasterNinja2 is not online. StickMasterNinja2
Joined: 18 May 2013
Total Posts: 1170
24 Jan 2015 05:13 PM
I changed Players to game.Players and still not work.
Report Abuse
StickMasterNinja2 is not online. StickMasterNinja2
Joined: 18 May 2013
Total Posts: 1170
24 Jan 2015 05:30 PM
Please, I need to finish the game.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
24 Jan 2015 05:33 PM
dont even go though players, just iterate though workspace for torsos and check it its a player
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
24 Jan 2015 05:33 PM
'dont even go though players, just iterate though workspace for torsos and check it its a player'

Thats not efficient
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
24 Jan 2015 05:34 PM
That's less efficient, Chimmihc.
Report Abuse
EliteDerper is not online. EliteDerper
Joined: 05 Feb 2012
Total Posts: 2288
24 Jan 2015 05:37 PM
game.Players ???
Report Abuse
EliteDerper is not online. EliteDerper
Joined: 05 Feb 2012
Total Posts: 2288
24 Jan 2015 05:37 PM
Players = game.Players


Add that in the beginning of your script
Report Abuse
StickMasterNinja2 is not online. StickMasterNinja2
Joined: 18 May 2013
Total Posts: 1170
24 Jan 2015 06:34 PM
Can't move too. There is something I forgot to make the AI walk?
Report Abuse
EliteDerper is not online. EliteDerper
Joined: 05 Feb 2012
Total Posts: 2288
25 Jan 2015 03:05 AM
To be honest, I don't think this is AI.
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