Having Problem with Boat Platform

Hello There!
I made a boat that can sail and found a script that can make players stand on platforms and even jump on them withough them falling off.
Code:

local Players = game:GetService("Players")
local player = game:GetService("Players").LocalPlayer or game.Players.PlayerAdded:Wait()
local Character = player.Character or player.CharacterAdded:Wait()
local RunService = game:GetService('RunService')

local LastTrainCFrame

local Function
local Function2


Function = RunService.Heartbeat:Connect(function()

	--------------------------------------------------------------- CHECK PLATFORM BELOW

	local RootPart = player.Character.HumanoidRootPart

	local Ignore = Character

	local ray = Ray.new(RootPart.CFrame.p,Vector3.new(0,-50,0))

	local Hit, Position, Normal, Material = workspace:FindPartOnRay(ray,Ignore)

	if Hit and Hit:FindFirstChild("Movable") then -- Change "RaftTop" to whatever the moving part's name is
		if Hit:FindFirstChild("Movable").Value == true then
		--------------------------------------------------------------- MOVE PLAYER TO NEW POSITON FROM OLD POSITION

		local Train = Hit
		if LastTrainCFrame == nil then -- If no LastTrainCFrame exists, make one!
			LastTrainCFrame = Train.CFrame -- This is updated later.
		end
		local TrainCF = Train.CFrame 

		local Rel = TrainCF * LastTrainCFrame:inverse()

		LastTrainCFrame = Train.CFrame -- Updated here.

		RootPart.CFrame = Rel * RootPart.CFrame -- Set the player's CFrame

	

		end
	else
		LastTrainCFrame = nil -- Clear the value when the player gets off.
end
	Function2 = player.Character.Humanoid.Died:Connect(function()
		Function:Disconnect() -- Stop memory leaks
		Function2:Disconnect() -- Stop memory leaks
	end)

end)

You put it in StarterPlayerScripts on a localscript.

But my problem is that it works perfectly with moving objects with cframe but my boat moves with bodyVelocity and bodyGyro and it doesnt perform the greatest.

Video:
robloxapp-20210825-2012052.wmv (5.8 MB)
When someone drives the boat the other players that are standing on the boat just go automaticaly frontwards when the driver drives frontwards and go backwards when the driver drives backwards.

Is there any way i can fix this?
Any help whould be greatly appreciated!

1 Like