|
| 04 Feb 2014 06:51 PM |
| How do i find the closes player or humanoid? |
|
|
| Report Abuse |
|
|
shawnyg
|
  |
| Joined: 21 Apr 2011 |
| Total Posts: 1428 |
|
|
| 04 Feb 2014 06:52 PM |
Um... explain.
~Hope I helped! If you need a script, PM me.~ ~The G~ ~CAT General Shawnyg~ |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2014 06:56 PM |
| I have an npc, i want to run an animation if a player is close to it. |
|
|
| Report Abuse |
|
|
shawnyg
|
  |
| Joined: 21 Apr 2011 |
| Total Posts: 1428 |
|
|
| 04 Feb 2014 06:57 PM |
Use magnitude.
http://wiki.roblox.com/index.php?title=Magnitude
~Hope I helped! If you need a script, PM me.~ ~The G~ ~CAT General Shawnyg~ |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2014 07:14 PM |
| o.O Some confusing stuff... |
|
|
| Report Abuse |
|
|
yurhomi10
|
  |
| Joined: 10 Dec 2008 |
| Total Posts: 13886 |
|
|
| 04 Feb 2014 07:15 PM |
magnitude is just the distance from your target to the other object.
i |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2014 07:34 PM |
Uh, ok. So how do i check if it's within for example 5 blocks of a player? Cause the wiki doesn't really help >.> |
|
|
| Report Abuse |
|
|
yurhomi10
|
  |
| Joined: 10 Dec 2008 |
| Total Posts: 13886 |
|
|
| 04 Feb 2014 07:34 PM |
google some videos or something
i dont know how to apply magnitude but I know what the term means. |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 04 Feb 2014 07:35 PM |
| I think theres a property called 'FindNearest--Object' |
|
|
| Report Abuse |
|
|
bibbs123
|
  |
| Joined: 03 Jun 2008 |
| Total Posts: 24994 |
|
|
| 04 Feb 2014 07:39 PM |
feeling helpful assuming this is placed inside of a humanoid
while wait() do a=game.Players:GetChildren() for i = 1, #a do if((a[i].Character.Torso.Position - script.Parent.Torso.Position).magnitude <= 5)then --Do whatever you want here end end end end |
|
|
| Report Abuse |
|
|
EgoMoose
|
  |
| Joined: 04 Feb 2009 |
| Total Posts: 2896 |
|
|
| 04 Feb 2014 07:41 PM |
Example:
function FindNearestHumanoid() local Distances ={} for i, v in ipairs(game.Players:GetChildren()) do local Char = v.Character if Char ~= nil then local Torso = Char:FindFirstChild("Torso") local Human = Char:FindFirstChild("Humanoid") if Torso ~= nil and Human ~= nil then if Human.Health > 0 then local Pos1 = Torso.Position * Vector3.new(1, 0, 1) local Pos2 = script.Parent.Position * Vector3.new(1, 0, 1) table.insert(Distances, (Pos1 - Pos2).Magnitude) end end end end if Distances[1] ~= nil then -- At least one value... if math.min(unpack(Distances)) <= Radius then -- The closest humanoid is the trigger -- Do whatever else -- Otherwise do something else end end end |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2014 07:41 PM |
| @Goulstem i couldn't find anything on wiki :/ |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2014 08:05 PM |
I tried both the scripts, not sure if i use :LoadAnimation correctly though..
while wait() do ani = Humanoid:LoadAnimation(script.Parent.Animation) a=game.Players:GetChildren() for i = 1, #a do if((a[i].Character.Torso.Position - script.Parent.Torso.Position).magnitude <5)then repeat ani:Play() wait(1) until ((a[i].Character.Torso.Position - script.Parent.Torso.Position).magnitude > 5) end end end --------------------------------------------------------------------------------------------------------------------------------- ani = script.Parent.Animation function FindNearestHumanoid() local Distances ={} for i, v in ipairs(game.Players:GetChildren()) do local Char = v.Character if Char ~= nil then local Torso = Char:FindFirstChild("Torso") local Human = Char:FindFirstChild("Humanoid") if Torso ~= nil and Human ~= nil then if Human.Health > 0 then local Pos1 = Torso.Position * Vector3.new(1, 0, 1) local Pos2 = script.Parent.Position * Vector3.new(1, 0, 1) table.insert(Distances, (Pos1 - Pos2).Magnitude) end end end end if Distances[1] ~= nil then if math.min(unpack(Distances)) <= Radius then repeat ani:Play() wait(1) until math.min(unpack(Distances)) > Radius end end end |
|
|
| Report Abuse |
|
|
| |
|
bibbs123
|
  |
| Joined: 03 Jun 2008 |
| Total Posts: 24994 |
|
|
| 04 Feb 2014 10:30 PM |
| Humanoid:LoadAnimation(animation object here):Play() |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2014 12:03 AM |
| Does it matter what the humanoid is called? |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2014 12:16 AM |
This is how it looks like so far....
while wait() do a=game.Players:GetChildren() for i = 1, #a do if((a[i].Character.Torso.Position - script.Parent.Torso.Position).magnitude <5)then repeat script.Parent.Zombie:LoadAnimation(script.Animation):Play() wait(1) until ((a[i].Character.Torso.Position - script.Parent.Torso.Position).magnitude > 5) end end end
Still doesn't work.. |
|
|
| Report Abuse |
|
|
| |
|
|
| 05 Feb 2014 05:39 AM |
| Not sure if this is really the issue withy our script, but I think it's because your if has no spaces. |
|
|
| Report Abuse |
|
|
bibbs123
|
  |
| Joined: 03 Jun 2008 |
| Total Posts: 24994 |
|
|
| 05 Feb 2014 10:01 AM |
the if has whitespace with the ()'s
you don't need the repeat until thing |
|
|
| Report Abuse |
|
|
bibbs123
|
  |
| Joined: 03 Jun 2008 |
| Total Posts: 24994 |
|
|
| 05 Feb 2014 10:04 AM |
while wait() do a=game.Players:GetChildren() for i = 1, #a do if((a[i].Character.Torso.Position - script.Parent.Torso.Position).magnitude <5)then script.Parent.Zombie:LoadAnimation(script.Animation):Play() wait(1) end end end
just make sure it waits however long the animation is and make sure that the animation is called Animation and is inside of the scipt |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2014 10:20 AM |
| @Goul you call everything the wrong thing. Calling a methid that doesn't even exist a property shows you do not know much basic Lua |
|
|
| Report Abuse |
|
|
| |
|
|
| 05 Feb 2014 11:59 AM |
It doesn't matter if it's not a player that is doing the animation right?
animName = "ExportAnim" animID = "http://www.roblox.com/asset/?id=144953589"
anim = script.Parent:FindFirstChild(animName) if anim == nil then anim = Instance.new("Animation") anim.Parent = script.Parent anim.AnimationId = animID elseif anim.AnimationId == "" then anim.AnimationId = animID end while wait() do a=game.Players:GetChildren() for i = 1, #a do if((a[i].Character.Torso.Position - script.Parent.Torso.Position).magnitude <5)then loadanim = script.Parent:FindFirstChild("Zombie"):LoadAnimation(anim) loadanim:Play() wait(1) end end end |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2014 12:05 PM |
| You could use DistanceFromCharacter method. |
|
|
| Report Abuse |
|
|