|
| 08 Jun 2014 09:40 AM |
I want to make a robot which detects a player. I know its something like this: local d = (v:findFirstChild("Torso").Position - script.Parent.Position).magnitude
But when the detected player dies and its torso disapears, the script stops working...
|
|
|
| Report Abuse |
|
|
ash877
|
  |
| Joined: 18 Feb 2008 |
| Total Posts: 5142 |
|
|
| 08 Jun 2014 09:42 AM |
| use a premade one from roblox's zombie model. |
|
|
| Report Abuse |
|
|
|
| 08 Jun 2014 10:05 AM |
| That robot doesnt have humanoid |
|
|
| Report Abuse |
|
|
| |
|
|
| 08 Jun 2014 11:23 AM |
um yeah,
well if a player dies, then v becomes nil, so u are going to get an error looking for anything, while supplying Nil, as the Modle to look in, so:
if v ~= Nil then local d = (v:findFirstChild("Torso").Position - script.Parent.Position).magnitude else --better find another Player end
Yeah, I agree with Ash, find a Zombie script which works, and tinker with that.
You don't start scripting, by scripting; you start scripting, by Modding.
GL, Bri
|
|
|
| Report Abuse |
|
|
|
| 08 Jun 2014 11:37 AM |
Here is a FindNearestTorso, which I converted to a Find Closest Player, but I wouldn't trust it. I'm getting some kind of occasional lag in the Modle I'm using it in (supply pos; where to measure from):
I saw a FindClosest one on the Forum, once, but could not find it again.
function findNearestTorso(pos) closest = 180 -- max area to search closestchar = nil for i,v in pairs(game.Players:GetChildren()) do if v.Character ~= nil then local temp = v.Character:findFirstChild("Torso") if temp then
local distance = (temp.Position - pos).magnitude -- THIS DOES NOT DETECT A pLAYER. tHIS MEASURES THE 3D DISTANCE FROM A POTENTIAL TARGET TO ORUGUN. if distance < closest then closest = distance closestchar = v.Character.Torso end -- closer? end -- torso? end -- Char? end -- list Dist = closest return closestchar end -- function |
|
|
| Report Abuse |
|
|
| |
|