Boat / train "CFrame replicating" not working correctly

Hey there!

I’m trying to make a boat move, and I did it. But, when I try to “replicate” the CFrame of the boat to the client, this happens.

This is my code on the client-side:

local rus = game:GetService("RunService")
local boatFolder = game.Workspace.Boat:WaitForChild("Cutter") -- The Boat on the workspace folder
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character
local lastCFrame

if not (char) then
	repeat
		warn("Character not found, waiting 0.2s and retrying.")
		char = plr.Character
		wait(0.2)
	until char
end

local rs = rus.Heartbeat:Connect(function()
	local root = char:WaitForChild("LowerTorso")
	local ray = Ray.new(root.CFrame.p, Vector3.new(0, -50, 0))
	local hit = game.Workspace:FindPartOnRayWithIgnoreList(ray, char:GetChildren())
	
	if (hit and hit:IsDescendantOf(boatFolder)) then
		local boat = hit
		
		if not (lastCFrame) then
			lastCFrame = boat.CFrame
		end
		
		local boatCF = boat.CFrame
		local rel = boatCF * lastCFrame:inverse()
		
		lastCFrame = boat.CFrame
		root.CFrame = rel * root.CFrame
	else
		lastCFrame = nil
	end
end)

char.Humanoid.Died:Connect(function()
	rs:Disconnect()
end)

If the same thing happened to someone, and you have been able to solve it, or someone who knows how to do it, please.

PS: The boat speed is 30.

Sorry if i didn’t read alot but from the first lines i can see the script is going wrong based on your ray
local ray = Ray.new(root.CFrame.p, Vector3.new(0, -50, 0))
As it goes to the position 0,-50,0 as a direction from the origin rootcframe