How can I make this follow script follow a part and a player depending on which is closer?
01 | local larm = script.Parent:FindFirstChild( "Left Arm" ) |
02 | local rarm = script.Parent:FindFirstChild( "Right Arm" ) |
04 | function findNearestTorso(pos) |
05 | local list = game.Workspace:children() |
13 | if (temp 2. className = = "Model" ) and (temp 2 ~ = script.Parent) then |
14 | temp = temp 2 :findFirstChild( "Torso" ) |
15 | human = temp 2 :findFirstChild( "Humanoid" ) |
16 | if (temp ~ = nil ) and (human ~ = nil ) and (human.Health > 0 ) then |
17 | if game.Players:GetPlayerFromCharacter(temp 2 ) then |
18 | if (temp.Position - pos).magnitude < dist then |
20 | dist = (temp.Position - pos).magnitude |
31 | local target = findNearestTorso(script.Parent.Torso.Position) |
33 | script.Parent.Humanoid:MoveTo(target.Position, target) |
-- This script makes a noob follow a player. How can I make it go to "game.Workspace.Gate" if it is closer to the gate and follow a player if its closer to a player?
I have been trying for an hour and have not gotten anything to work. I tried to do a
do blah()
else if blah magnitude > blag then
do blah()
--Thanks