I was trying to make a boat system but got stuck with even moving it forward/backward and also having a problem with it flipping over
Server Script:
local Boat = script.Parent
local VehicleSeat = Boat.VehicleSeat
local AlignPos = Boat.PrimaryPart.AlignPosition
VehicleSeat:GetPropertyChangedSignal("Throttle"):Connect(function()
local x = AlignPos.Position.X
local y = AlignPos.Position.Y
local z = AlignPos.Position.Z
AlignPos.Position = Vector3.new(
x,
y,
z * -VehicleSeat.Throttle * 0.5
)
end)
Model:
Problem
It moves forward but how can i do it for backwards too?
flips boat if the player jumps on the edge of the boat
Only goes in one direction and doesnât stop until it reaches its destination
There are so many posts about boats already. Try the Search button up top.
Are you using Terrain Water? Iâve got quite a few solutions on boat topics that Iâve posted on to keep the boat from flipping.
If you arenât using Water then you need an AlignOrientation to keep it level. You can also use it to steer the boat.
Also, just put the script in the seat and use vehicleSeat = script.Parent.
Itâs a good idea to not use actual names of items as Variable names. Just make the capital letter a small case letter.
Honestly Iâd just rewrite the code its messy and rather complicated. My version, where the AlignPosition continues to use OneAttachment
local seat = script.Parent -- Script is in vehicle seat
local boat = seat.Parent.PrimaryPart -- Boat model's main part
local ap = boat.AlignPosition -- Align position which is connected to a attachment in the boat's main part
local isholding; local speed = 10
seat:GetPropertyChangedSignal("ThrottleFloat"):Connect(function() -- Throttle is deprecated
local tf = seat.ThrottleFloat
if tf == 0 then isholding = false else isholding = true end
while isholding do
ap.Position = boat.Position + boat.CFrame.LookVector * speed * tf
task.wait()
end
end)
Basically the code operates in a while loop that runs only when the player is holding either movement key. The align position will move parallel to the direction its facing ,speed studs, with tf determining whether it should move forward or back (its either 1 or -1). If the player stops holding (tf = 0), the flag will be false so theyâll stop moving. The same logic can be used for steering