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: Find humanoid

Previous Thread :: Next Thread 
GraniteSphere is not online. GraniteSphere
Joined: 09 Aug 2012
Total Posts: 237
04 Feb 2014 06:51 PM
How do i find the closes player or humanoid?
Report Abuse
shawnyg is not online. 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
GraniteSphere is not online. GraniteSphere
Joined: 09 Aug 2012
Total Posts: 237
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 is not online. 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
GraniteSphere is not online. GraniteSphere
Joined: 09 Aug 2012
Total Posts: 237
04 Feb 2014 07:14 PM
o.O Some confusing stuff...
Report Abuse
yurhomi10 is not online. 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
GraniteSphere is not online. GraniteSphere
Joined: 09 Aug 2012
Total Posts: 237
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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
GraniteSphere is not online. GraniteSphere
Joined: 09 Aug 2012
Total Posts: 237
04 Feb 2014 07:41 PM
@Goulstem i couldn't find anything on wiki :/
Report Abuse
GraniteSphere is not online. GraniteSphere
Joined: 09 Aug 2012
Total Posts: 237
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
GraniteSphere is not online. GraniteSphere
Joined: 09 Aug 2012
Total Posts: 237
04 Feb 2014 08:16 PM
Bump :/
Report Abuse
bibbs123 is not online. bibbs123
Joined: 03 Jun 2008
Total Posts: 24994
04 Feb 2014 10:30 PM
Humanoid:LoadAnimation(animation object here):Play()
Report Abuse
GraniteSphere is not online. GraniteSphere
Joined: 09 Aug 2012
Total Posts: 237
05 Feb 2014 12:03 AM
Does it matter what the humanoid is called?
Report Abuse
GraniteSphere is not online. GraniteSphere
Joined: 09 Aug 2012
Total Posts: 237
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
GraniteSphere is not online. GraniteSphere
Joined: 09 Aug 2012
Total Posts: 237
05 Feb 2014 05:34 AM
Anyone got a sulution?
Report Abuse
Wreckerbuster67 is not online. Wreckerbuster67
Joined: 29 Jul 2012
Total Posts: 1144
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 is not online. 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 is not online. 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
Solsticedev is not online. Solsticedev
Joined: 02 Feb 2014
Total Posts: 343
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
Solsticedev is not online. Solsticedev
Joined: 02 Feb 2014
Total Posts: 343
05 Feb 2014 10:21 AM
method*
Report Abuse
GraniteSphere is not online. GraniteSphere
Joined: 09 Aug 2012
Total Posts: 237
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
FreeScriptMaker is not online. FreeScriptMaker
Joined: 29 Nov 2013
Total Posts: 2275
05 Feb 2014 12:05 PM
You could use DistanceFromCharacter method.
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