Boat Script not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A boat script i’m making to float on a part is not working, as it simply goes through the part i need to float on, it also has a lot other issues, but that is the main one that is being very frustrating to fix.

  2. What is the issue? Include screenshots / videos if possible!
    this is the script that is causing the issue:

local Engine = script.Parent.Parent.Engine.BodyThrust -- The force making the boat move
local DSeat = script.Parent -- The driver seat
local Base = script.Parent.Parent.Base -- The base part of the boat

local speed = 1000 -- The force of 'Engine'
local SteerSpeed = 5 -- The speed at which the boat turns
local BaseDensity = 0.1 -- Lower this if your boat can't float, make it higher to make it go more in the water
local dampingFactor = 0.98 -- Factor to slow down the boat when throttle is not engaged
local maxSpeed = 50 -- Maximum speed of the boat

-- Reference to the target part in the workspace
local targetPart = workspace:WaitForChild("TargetPart")

-- Create AlignPosition to maintain the Y-axis
local alignPosition = Instance.new("AlignPosition")
alignPosition.MaxForce = 50000 -- Set a high force to keep the boat stable
alignPosition.RigidityEnabled = true
alignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment
alignPosition.Position = Base.Position
alignPosition.Parent = Base

-- Create AlignOrientation to lock the boat's orientation
local alignOrientation = Instance.new("AlignOrientation")
alignOrientation.MaxTorque = Vector3.new(math.huge, math.huge, math.huge) -- Lock all axes
alignOrientation.Responsiveness = 200
alignOrientation.PrimaryAxisOnly = false
alignOrientation.Parent = Base

local throttleEngaged = false
local steerInput = 0

DSeat.Changed:Connect(function(p)
    if p == "ThrottleFloat" then
        throttleEngaged = (DSeat.ThrottleFloat ~= 0)
        -- Calculate the desired engine force
        local desiredForce = speed * DSeat.ThrottleFloat
        -- Limit the boat's speed to maxSpeed
        if Base.Velocity.Magnitude < maxSpeed then
            Engine.Force = Vector3.new(0, 0, desiredForce)
        else
            Engine.Force = Vector3.new(0, 0, 0)
        end
    end

    if p == "SteerFloat" then
        steerInput = DSeat.SteerFloat
    end

    if p == "Occupant" then
        if not DSeat.Occupant then
            -- Correct orientation when player leaves the boat
            Base.CFrame = CFrame.Angles(0, 0.104, 0)
        else
            -- Correct orientation when player enters the boat
            alignOrientation.CFrame = Base.CFrame
        end
    end
end)

Base.CustomPhysicalProperties = PhysicalProperties.new(BaseDensity, 0, 0)

-- Ensure the boat maintains the desired Y-axis position and orientation
game:GetService("RunService").Stepped:Connect(function()
    -- Update the AlignPosition to lock the Y-axis to the target part's Y-axis, offset by 1
    local targetY = targetPart.Position.Y + 1
    alignPosition.Position = Vector3.new(Base.Position.X, targetY, Base.Position.Z)

    -- Apply steering hold
    if steerInput ~= 0 then
        local newOrientation = Base.CFrame * CFrame.Angles(0, math.rad(-SteerSpeed * steerInput), 0)
        Base.CFrame = newOrientation
    end

    -- Apply damping to slow down the boat constantly
    Engine.Force = Engine.Force * dampingFactor

    -- Apply additional damping when the throttle is not engaged
    if not throttleEngaged then
        Base.Velocity = Base.Velocity * dampingFactor
    end
end)

This is the explorer of the boat, the WaterLevel part is in Workspace:
Screenshot 2025-03-05 144948

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried changing a lot of the parts, and nothing works, this issue is a script itself issue, so I couldn’t find anything online.

Any help is extremely appreciated, I have came here as a last resort for this issue.

2 Likes

It doesn’t look like you set the alignPosition.Attachment0 or alignPosition.Attachment1.

Without the attachments, neither the alignPosition nor the alignOrientation know what they’re meant to position/orient.