Npc Defend an Attack

Hello
I’m trying to make an Npc react to attacks, tho any of my attempts worked
I’m trying to check if rng = 3 then check if “M1” is a child of the enemy

char is the player’s/Enemy model
Rng is the rng to determine if the npc will attack or defend:

if rng == 1 then
hit()
end

if rng >= 2 then
Defend()
end

What I have right now is:

if rng >=2 then
Defend()
end

What I have tried so far was:

if rng >=2 then
if char:FindFirstChild("M1") then
Defend()
end
end

And

If rng >=2 then
char.ChildAdded:Connect(function(child)
if child.Name = "M1" then
Defend()
end
end)
end

M1 object is created when the tool is fired and destroyed fairly quickly so how can I make the npc check if the enemy is attacking or not?

you need to make it

if rng <=2 then

instead of

if rng = 1 then

and also you need to make it

if rng == 3 then

idk if this will fix all the problems, but it is a big issue

Found a fix, wasn’t exactly that but thanks for the help