Hello, how would I get a zombie furthest on a given path, for instance I want to basically make an object target the further / first zombie on the path. I’ve tried to do it myself but the code just gets the zombie with the longest amount of time on the path. Here is my current code:
Get the magnitude from the position, then subtract it from the part you are checking. Save all the results in a table and then check which one is the closest one (Note use math.abs(result) so that the result is positive)
task.spawn(function()
while task.wait() do
local PosNum = (Vector3.new(obj:FindFirstChild("HumanoidRootPart").Position.X, workspace:WaitForChild("GameItems").Spawn.Spawn.Position.Y, obj:FindFirstChild("HumanoidRootPart").Position.Z).Magnitude - obj:GetAttribute("Position"))
obj:SetAttribute("Position", PosNum)
end
end)
task.spawn(function()
while task.wait() do
local PosNum = math.abs(obj:FindFirstChild("HumanoidRootPart").Position.Magnitude - obj:GetAttribute("Position").Magnitude)
obj:SetAttribute("Position", PosNum)
end
end)
task.spawn(function()
while task.wait() do
local PosNum = (obj:FindFirstChild("HumanoidRootPart").Position - obj:GetAttribute("Position")).Magnitude
obj:SetAttribute("Position", PosNum)
end
end)
for i, target in pairs(workspace:WaitForChild("GameItems").Mobs:GetChildren()) do
local distance
if Tower then
distance = (target.HumanoidRootPart.Position - Tower.PrimaryPart.Position).Magnitude
end
if distance < maxDistance then
table.insert(targetList, target)
end
end
for _, target in pairs(targetList) do
if not firstTarget then
if target:GetAttribute("Hidden") and data.HiddenDetection or not target:GetAttribute("Hidden") then
firstTarget = target
else
continue
end
else
if target:GetAttribute("Hidden") and data.HiddenDetection or not target:GetAttribute("Hidden") then
if firstTarget:GetAttribute("Position") < target:GetAttribute("Position") then
firstTarget = target
end
else
continue
end
end
end