Hi, I've been messing around with npcs from roblox that chase and attack you, but i've been trying to make it so you can summon an npc that attacks people for you when you use an ability, but the thing is, it doesn't go for the player, but if the player is closest to the noob it won't attack anyone else, as it only attacks the person closest to it, which in this case is the summoner.
In my script for summoning it, I put a string value inside the noob and made it say the name of the player because the chase script is inside the noob, not the summon script.
anyways, here is the chase script inside the noob. Help would be really appreciated!
local larm = script.Parent:FindFirstChild("HumanoidRootPart") local rarm = script.Parent:FindFirstChild("HumanoidRootPart") local summoner = script.Parent:WaitForChild("Owner") function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 10000 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) then temp = temp2:findFirstChild("HumanoidRootPart") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end while true do wait(1) local target = findNearestTorso(script.Parent.HumanoidRootPart.Position) if target ~= nil and target.Parent.Name == summoner.Value then print("Target not found") elseif target ~= nil and target.Parent.Name ~= summoner.Value then print("Target Found") script.Parent.Humanoid:MoveTo(target.Position, target) end end
Try using
if (temp2.className == "Model") and (temp2 ~= script.Parent) and temp2.Name ~= summoner.Value then
if (temp2.className == "Model") and (temp2 ~= script.Parent) and temp2 ~= summoner.Value then