Multi CFrame tasking bug

I’m trying to make a boat follow a route of bricks using CFrame, but have some weird problems with it. The boat contains a script along with it which controls the Y-Axis to move with water waves. The part rotates aswell along with the waves. Now the red part is the part which follows the route, and creates the waving effect. The green part is attached to the red part using a HingeConstraint. It’s pretty hard to explain, but this shows the problem:
https://gyazo.com/eaa283da9c4a61e37e25677281c432c5
It works all fine when I have the waving effect disabled. ^
https://gyazo.com/b23d8adea63f4cc6f08814258ae6e4e2
This happens when I re-enable it. ^

I tried turning all collisions off and all, but without success.

The waving script:

local waveWidth = 85;
local waveHeight = workspace.Terrain.WaterWaveSize * 2;
--while _G.GetWaterWaveCycle == nil do wait()
--end
function height(x, z, cycle)
	return waveHeight * math.sin(2*math.pi*x/waveWidth + cycle + math.pi/2)
		* math.sin(2*math.pi*z/waveWidth);
end

game:GetService("RunService").Heartbeat:Connect(function(p1)
	while true do
	wait()
	if _G.GetWaterWaveCycle ~= nil then
	local d = _G.GetWaterWaveCycle()
	--print(d)
	_G.GetWaterWaveCycle()
	local c = height(script.Parent.Position.X, script.Parent.Position.Z, d + 3 *2)
	print(c)
	local APP =  CFrame.new (
	      script.Parent.CFrame.X,
		  c/(script._CNF._APlX.Value),
		  script.Parent.CFrame.Z
			)
			--print(APP)
	script.Parent.CFrame = APP
	script.Parent.Orientation = Vector3.new(c/(script._CNF._APlX.Value), c/(script._CNF._APlX.Value), c/(script._CNF._APlX.Value))
    --script.Parent.Position = Vector3.new(script.Parent.Position.X, c, script.Parent.Position.Z)
		end
		end
	wait(p1)
end)

The route script:

local d = require(script.Parent.ModuleScript)
local vd = d.wv
while true do
for i = script.TargetPoint.Value, script.EndPoint.Value do -- The route is numbered
	local v = game.Workspace.Track:WaitForChild(i)
	local waitingtime = vd
	
	if v:FindFirstChild("CustommTime") then
		waitingtime = v.CustomTime.Value
	else
		waitingtime = 1 --normal wait time
	end
	
	local TweeningInformation = TweenInfo.new(
		waitingtime,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.InOut,
		0,
		false,
		0
		)
	local Props = {
			CFrame = CFrame.new(
		Vector3.new(
		v.CFrame.X,
		script.Parent.CFrame.Y,
		v.CFrame.Z))
		}
	local Tweenservice = game:GetService("TweenService")
	local Movement = Tweenservice:Create(script.Parent,TweeningInformation,Props)
	Movement:Play()
	script.CurrentPoint.Value = v.Name
	wait(waitingtime)
	end
end

Could it be that the CFrame is glitched out?

I don’t understand why you’re using a loop inside a loop basically, I mean, why not just using Heartbeat exchange while true do??

try slapping a couroutine.wrap and see if that fixes it? If it does, you may have to change some things around, the code is a tad messy though, may want to clean it up.

I removed it, now it’s giving a different effect:
https://gyazo.com/fd5b0d9c5a84c14bbad02b61b8afbd13

How and where would I implement that in my script? And yeah sorry for the messy scripts, thought it would be quite easy to troubleshoot the problem.