|
| 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 |
|
|
|
| 24 Jan 2015 04:10 PM |
| Well then define it so that it doesn't have a problem. |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:21 PM |
| Please, I need a solution of this error. |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:23 PM |
Just define it somewhere.
http://wiki.roblox.com/index.php?title=Variables |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 24 Jan 2015 05:13 PM |
| I changed Players to game.Players and still not work. |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 05:30 PM |
| Please, I need to finish the game. |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 24 Jan 2015 05:34 PM |
| That's less efficient, Chimmihc. |
|
|
| Report Abuse |
|
|
| |
|
|
| 24 Jan 2015 05:37 PM |
Players = game.Players
Add that in the beginning of your script |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 06:34 PM |
| Can't move too. There is something I forgot to make the AI walk? |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2015 03:05 AM |
| To be honest, I don't think this is AI. |
|
|
| Report Abuse |
|
|