# For some reason the npc isnt attacking

I’m trying to make it so that my npc attacks you when you get too close, when i try to do this it doesn’t work
heres the code

``````if GameUtility.CheckPointOnCircle(Position, HumanoidRootPart.Position >= 100) then
BossInformation["State"] = MobStates[4]

if HumanoidRootPart.Position - HumanoidRootPart.Position <=10 and MobStates[4] then
Module:Attack()`````````

You have to use magnitude:

``````if (HumanoidRootPart.Position - HumanoidRootPart.Position).Magnitude <=10 and MobStates[4] then
``````

Magnitude defines the length of a vector, therefore the length of a vector minus a vector would be the distance.

Edit: Also, you’re doing subtraction on the same vector, I’m confused on why you’re doing this?

Yeah that was an accident i just realized it

Position returns a vector3, so I’m confused on why you’re comparing it to a number.

``````if GameUtility.CheckPointOnCircle(Position, HumanoidRootPart.Position >= 100) then
``````

Corrected everything, still nothing

``````			BossInformation["State"] = MobStates[4]
if GameUtility.CheckPointOnCircle(Position, HumanoidRootPart.Position,100) then
BossInformation["State"] = MobStates[4]

if (HumanoidRootPart.Position - BossRootPart.Position).Magnitude  <=10 and MobStates[4] then
self:Attack()``````

Try to print out “MobStates[4]” or really just add print statements around this part of the code, and if they don’t print something’s wrong.

I have, ill send you the full code

What did MobStates[4] print out?

Print BossInformation[“State”] lmk what it prints out. Put the print statement AFTER where you set the State to MobStates[4].

Doesn’t print

``````			print(MobStates[4])
print(BossInformation[MobStates])
if GameUtility.CheckPointOnCircle(Position, HumanoidRootPart.Position,100) then
BossInformation["State"] = MobStates[4]

if (HumanoidRootPart.Position - BossRootPart.Position).Magnitude  <=10 and MobStates[4] then
self:Attack()
`````````

Try to put it after calling the CheckPointOnCircle function.

Still nothing, i think theres aproblem a few lines before so ill be using prints

There’s a problem with the State change, review your CheckPointOnCircle function. If you mind, could I look at the CheckPointOnCircle function?

``````function Module.CheckPointOnCircle(CenterPosition, CheckingPosition, Radius)
local CheckPositionX = math.abs((CheckingPosition.X - CenterPosition.X))
local CheckPositionZ = math.abs((CheckingPosition.Z - CenterPosition.Z))

if (CheckPositionX + CheckPositionZ <= Radius) or (CheckPositionX^2) + (CheckPositionZ^2) <= (Radius^2)  then
return true
else
return false
end
end``````

Print the function, does it print “true”?

It doesn’t print anything ((((((((((((((((

Print the function itself, when the Checking Position has the conditions for it to be true. At the start of the code.