You can write your topic however you want, but you need to answer these questions:
Hey guys, I’m working on a game sort of like combat rift, and can’t seem to figure out how to make an NPC be passive until damaged. Any help?
I have tried using a “script.Parent.HealthChanged:Wait()” but it didnt work, only teleported the NPC onto your head.
My script:
local larm = script.Parent:FindFirstChild("LeftUpperArm")
local rarm = script.Parent:FindFirstChild("RightUpperArm")
script.Parent.HealthChanged:Wait()
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 100
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(0.1)
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
script.Parent:MoveTo(target.Position, target)
end
end
Anything I should change/fix? Thanks!