Need help making a ridable ship

I made a wave system using skinned mesh and managed to make the boat float on it, but I’m having problems making the ship controllable while floating. Here is the code to make it float:

local Object = workspace:WaitForChild("Pirate")
local module = require(game:GetService("ReplicatedStorage"):WaitForChild("Wave"))
local rs = game:GetService("RunService")
local main = Object.primary

rs.Heartbeat:Connect(function(DeltaTime)
	local PlatformCF = main.main.CFrame
	local PlatformPosition = PlatformCF.Position

	local BackPosition = (PlatformCF * main.back.CFrame).Position
	local FrontPosition = (PlatformCF * main.front.CFrame).Position
	local LeftPosition = (PlatformCF * main.left.CFrame).Position
	local RightPosition = (PlatformCF * main.right.CFrame).Position

	BackPosition = Vector3.new(BackPosition.X, module.GetHeightAtXZ(BackPosition), BackPosition.Z)
	FrontPosition = Vector3.new(FrontPosition.X, module.GetHeightAtXZ(FrontPosition), FrontPosition.Z)
	LeftPosition = Vector3.new(LeftPosition.X, module.GetHeightAtXZ(LeftPosition), LeftPosition.Z)
	RightPosition = Vector3.new(RightPosition.X, module.GetHeightAtXZ(RightPosition), RightPosition.Z)

	local FinalCFrame = CFrame.new((BackPosition + FrontPosition + LeftPosition + RightPosition) / 4, (FrontPosition + RightPosition) / 2)
	Object:PivotTo(FinalCFrame)
end)
1 Like