Hello i am trying to get NPCs to fight each other based around attack distances something i have noticed is sometimes the NPCs move slightly to far causing the NPCs to appear facing back to back. I have programmed them to have no walkspeed if they are within attack radius and am trying to get them to correct them selves using ":SetPrimaryPartCFrame()" but i keep getting this error "Unable to cast Vector3 to CoordinateFrame"
Heres the line of code:
child:SetPrimaryPartCFrame(HRP.Position - eHRP.Position)
If anyone knows how i can adjust this to get it to function like it is suppose to I'd really appreciate it.
P.S: I have tried using:
child:SetPrimaryPartCFrame(HRP.Position.X - eHRP.Position.X,HRP.Position.Y - eHRP.Position.Y,HRP.Position.Z - eHRP.Position.Z)
And it still doesn't want to work (same error)
THIS IS NOT A REQUEST
The reason why this error happens is because you're passing a vector3, when it needed a CFrame, and you're trying to make the npc face the other the wrong way.
CFrames have a constructor that will help you:
CFrame.new(
Vector3 Pos,
Vector3 lookAt
)
This will return a CFrame situated as Pos and will face lookAt
Try this:
child:SetPrimaryPartCFrame(CFrame.new(HRP.Position, eHRP.Position))
The error is pretty clear. SetPrimaryPartCFrame expects a CFrame and you're providing it with "HRP.Position" which is a Vector3 (i.e. contains only X, Y, Z coords).
A CFrame and a Vector3 is not the same thing. CFrames contain a Vector3 AND an orientation whereas a Vector3 is...just a Vector3.
I'm not sure what you need but you can cast it to a CFrame by adding a new CFrame instance or using the current primary part CFrame:
CFrame.new() + (HRP.Position - eHRP.Position)
This creates a CFrame without preserving the character's orientation and moves it to the new world position.
child.PrimaryPart.CFrame + HRP.Position
This creates a new CFrame and translates it using the Vector3 "HRP.Position."
http://wiki.roblox.com/index.php?title=CFrame#CFrame_.2A_Vector3
*I have not tested this code