local hum = script.Parent:WaitForChild("Humanoid") local root = script.Parent:WaitForChild("HumanoidRootPart") local spawnpos = script.Parent:WaitForChild("SpawnPosition")
local visionrange = 99999 local attackrange = 3 local abandonrange = 999 local abandonrangefromhome = 999
local target = nil
while wait(1) do
if target then local plrRoot = target.humanoidrootpart local distance = (root.potition - plrRoot.position).magnitude local distancefromhome = (spawnpos.value - plrRoot.position).magnitude hum:moveto(plrRoot.Position - CFrame.new(root.position, plrRoot.position).lookvector * attackrange) if distance <= attackrange + 2 then script.AttackRemote:fire(plrRoot) end if distance > abandonrange then print("abandoning target") target = nil hum:moveto(spaenpos.value) end if distancefromhome > abandonranefromhome then print("abandoning target") target = nil hum:moveto(spaenpos.value) end else for i,v in pairs(game.players:getchildren()) do if not game.Workspace:FindFirstChild(v.name) then continue end local char = game.Workspace[v.name] local plrRoot = char.humanoidrootpart local distance = (root.potition - plrRoot.position).magnitude local distancefromhome = (spawnpos.value - plrRoot.position).magnitude if distance < visionrange and distancefromhome then print("targeting"..v.name) target = char end end end
end
Its uppercase P for Players on line 27