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 » Scripting Helpers
Home Search
 

Re: Magnitude help?

Previous Thread :: Next Thread 
masterjosue1998 is not online. masterjosue1998
Joined: 21 Feb 2011
Total Posts: 949
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 is not online. 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
masterjosue1998 is not online. masterjosue1998
Joined: 21 Feb 2011
Total Posts: 949
08 Jun 2014 10:05 AM
That robot doesnt have humanoid
Report Abuse
masterjosue1998 is not online. masterjosue1998
Joined: 21 Feb 2011
Total Posts: 949
08 Jun 2014 10:29 AM
...
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
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
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
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
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
08 Jun 2014 11:38 AM
*ORIGIN
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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