local char = nil
script.Parent.View.Touched:Connect(function(prt)
local hum = prt.Parent:FindFirstChild("Humanoid") --Player's humanoid
if hum then
if char == nil then
char = prt.Parent
end
end
end)
while wait() do
if char ~= nil then
script.Parent.Enemy:MoveTo(char.Torso.Position) --Enemy is the humanoid for the the NPC
if char.Humanoid.Health <= 0 then
print("dead")
char = nil
end
end
end
local char = nil
script.Parent.View.Touched:Connect(function(prt)
if prt.Parent:FindFirstChild("Humanoid") and char == nil then
char = prt.Parent
end
end)
while wait() do
if char ~= nil then
script.Parent.Enemy.Humanoid:MoveTo(char.HumanoidRootPart.Position)
if char.Humanoid.Health <= 0 then
print("dead")
char = nil
end
end
end