Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a humanoid follow players and not other humanoids?

Asked by 7 years ago

Heres a script I found

01local larm = script.Parent:FindFirstChild("Left Arm")
02local rarm = script.Parent:FindFirstChild("Right Arm")
03 
04function findNearestTorso(pos)
05    local list = game.Workspace:children()
06    local torso = nil
07    local dist = 20
08    local temp = nil
09    local human = nil
10    local temp2 = nil
11    for x = 1, #list do
12        temp2 = list[x]
13        if (temp2.className == "Model") and (temp2 ~= script.Parent) then
14            temp = temp2:findFirstChild("Torso")
15            human = temp2:findFirstChild("Humanoid")
View all 33 lines...

It follows npcs as well as players. How can I make it only follow players? I have tried inserting "if blah:IsA("Player") but it didnt work. - Thanks

1 answer

Log in to vote
0
Answered by 7 years ago

Hopefully this works.

01local larm = script.Parent:FindFirstChild("Left Arm")
02local rarm = script.Parent:FindFirstChild("Right Arm")
03 
04function findNearestTorso(pos)
05    local list = game.Workspace:children()
06    local torso = nil
07    local dist = 20
08    local temp = nil
09    local human = nil
10    local temp2 = nil
11    for x = 1, #list do
12        temp2 = list[x]
13        if (temp2.className == "Model") and (temp2 ~= script.Parent) then
14            temp = temp2:findFirstChild("Torso")
15            human = temp2:findFirstChild("Humanoid")
View all 35 lines...
1
Thanks man it works birdeater11 14 — 7y
0
Awesome, glad to hear. Hope you can see what I did and implement it yourself on your next project. protectiveebob 221 — 7y
Ad

Answer this question