How do you make the Model's CFrame Set to another Part?

Hi Other Developers,
Currently I’m trying to make a kind of TDS game and make the NewTurret follow it’s base part.
But the error I’m running to is the CFrame of a model to it’s primarypart,
this is what i have so far:

local function CreateTurret(TurretID)
	if TurretID == 1 then

		local NewTurret = Turrets.TurretFirst:Clone()
		NewTurret.Parent = NewTurretFolder
		
		local TurretBasePart = NewTurret:WaitForChild("TurretBasePart")
		
		coroutine.wrap(function()
			
			while true do
				if PlayerMouse.Button1Down == true then

					local OrginalBasePartLocation = TurretBasePart.Position
					TurretBasePart.Position = OrginalBasePartLocation
					NewTurret.TurretPart.Position = TurretBasePart.Position
					return

				end
				task.wait()
				
			end
		end)
		
		PlayerMouse.Move:Connect(function()
			
			TurretBasePart.Position = Vector3.new(PlayerMouse.Hit.Position.X, 0, PlayerMouse.Hit.Position.Z)
			NewTurret:PivotTo(CFrame.new( TurretBasePart.Position.X, TurretBasePart.Position.Y, TurretBasePart.Position.Z ))
			task.wait()
			
		end)

	end
end

And the Code Inside Im trying to change is

PlayerMouse.Move:Connect(function()
			TurretBasePart.Position = Vector3.new(PlayerMouse.Hit.Position.X, 0, PlayerMouse.Hit.Position.Z)
			NewTurret:PivotTo(CFrame.new( TurretBasePart.Position.X, TurretBasePart.Position.Y, TurretBasePart.Position.Z ))
			task.wait()
end)

Thanks!

can you send a screenshot of the error please?

Oh its not coming out with an error, the NewTurret model just doesn’t follow the TurretBasePart im trying to pivot it to.

I think I know the error.
Instead of directly calling coroutine.wrap(function() make a separate function using everything that you wrote in the coroutine function. call it with coroutine.wrap(awesomeFunction). I think this should fix it, because everytime i directly called a coroutine my function would simply just not run. Tell me if you don’t understand lol, English is not my native language.

I understand, but the code that’s changing the Turrets CFrame is outside of the coroutine.wrap function : P

oh, didn’t notice. Well, I don’t think I know how to solve it. Maybe include video of it might help me