Issues with CFrame

When the CFrame of this script is set, the entire model just teleports off of the map. Said model is rotating towards an equally sized part, from another model who does the same thing when it’s script is run. Is there a more efficient way of rotating a model to face another model, or at least some way to mitigate or completely stop the teleportation from happening?

for i, v in pairs(game.Workspace:GetChildren()) do
local humanoid = v:FindFirstChildOfClass(“Humanoid”)
local torso = v:FindFirstChild(“UpperTorso”)
local allied = “America_Rifler”
local range = Vector3.new(250, 5, 10)
if v:IsA(“Model”) and humanoid and torso then
if range.Magnitude >= v.HumanoidRootPart.Position.Magnitude then
if v.HumanoidRootPart.Parent == script.Parent and v.Humanoid.Health >= 0 and v.Name ~= allied then
print(“impossible”)
else
while wait(.1) do
script.Parent.HumanoidRootPart.CFrame = CFrame.new(script.Parent.HumanoidRootPart.Position, v.HumanoidRootPart.Position)
if v.Humanoid.Health <= 0 then
if script.Parent.Value.Value == true then
script.Parent.Value.Value = false
break;
end
end
end
end
end
end
end

What’s going on with the CFrame in this line?
script.Parent.HumanoidRootPart.CFrame = CFrame.new(script.Parent.HumanoidRootPart.Position, v.HumanoidRootPart.Position)

I couldn’t find anything that matched up with that format here:

I think if you are just trying to rotate the model you should use its Position and Rotation, not it’s Position twice.

Please write your code in this format.

/```lua

(with out the ‘/’)

With that we can read your code better and help you.

I noticed you used ‘and’ here, although I think you should use or. It currently only prints “impossible” when the player is dead, not allied and the script is parented to them. If you used ‘or’ in place of ‘and’, it would be if the player is the one the script is in or the player is dead or the player is not allied. This isn’t to do with the CFrame problem, but it’s still probably a bug in the code.

[edit] I posted my solution below

I think you are trying to define the CFrame with 2 positions, the orignal position is already defined and you should be overwritting it with the new position, try script.Parent.HumanoidRootPart.CFrame = v.HumanoidRootPart.CFrame

This will teleport the 1st player to the 2nd player with the same rotation.

Thank you for your help, I think I am understanding how CFrame works a bit better. However I need to rotate the model to face another model, and I am confused on that mainly.