local re = game.ReplicatedStorage:WaitForChild("re") local boat = script.Parent local bounce = false function goForward(move, speed) move.Parent = boat.basepart1 move.MaxForce = Vector3.new(math.huge,0,math.huge) move.Velocity = speed boat.basepart1.Velocity = speed boat.stats.acceleration.Value = 1 bounce = true while boat.stats.forward.Value == true do wait(0.5) move.Velocity = boat.basepart1.CFrame.lookVector*(move.Velocity.magnitude+boat.stats.acceleration.Value) if boat.stats.acceleration.Value <= 4.6 and boat.basepart1.Velocity.magnitude < 36 then boat.stats.acceleration.Value = boat.stats.acceleration.Value + 0.3 end end bounce = false boat.stats.acceleration.Value = 1 while boat.stats.forward.Value == false and boat.basepart1.Velocity.magnitude > 2.9 do wait(0.5) print(boat.basepart1.Velocity.magnitude," ",boat.stats.acceleration.Value) move.Velocity = move.Velocity - Vector3.new(boat.basepart1.CFrame.lookVector.x, 0, boat.basepart1.CFrame.lookVector.z)*boat.stats.acceleration.Value if boat.stats.acceleration.Value <=5 then boat.stats.acceleration.Value = boat.stats.acceleration.Value + 1 end end if boat.basepart1.Velocity.magnitude < 4.6 then move.Velocity = Vector3.new(0,0,0) end end function turn(move, direction) if direction == "a" then while direction == "a" and boat.stats.turning.Value == true do wait() boat:SetPrimaryPartCFrame(boat.PrimaryPart.CFrame * CFrame.Angles(0,0.004,0)) end elseif direction == "d" then while direction == "d" and boat.stats.turning.Value == true do wait() boat:SetPrimaryPartCFrame(boat.PrimaryPart.CFrame * CFrame.Angles(0,-0.004,0)) end end end re.OnServerEvent:connect(function(player, input, stroke) if boat.stats.driver.Value == "" then boat.stats.driver.Value = tostring(player) end if (tostring(player)) == boat.stats.driver.Value then if input and stroke then if input == "w" and stroke == "press" and bounce == false then bounce = true boat.stats.lastSpeed.Value = boat.basepart1.BodyVelocity.Velocity boat.stats.forward.Value = true goForward(boat.basepart1.BodyVelocity, boat.basepart1.BodyVelocity.Velocity) elseif input == "w" and stroke == "release" then boat.stats.lastSpeed.Value = boat.basepart1.BodyVelocity.Velocity boat.stats.forward.Value = false elseif input == "a" and stroke == "press" then boat.stats.turning.Value = true turn(boat.basepart1.turn, "a") elseif input == "d" and stroke == "press" then boat.stats.turning.Value = true turn(boat.basepart1.turn, "d") elseif input == "a" and stroke == "release" then boat.stats.turning.Value = false --stopTurn(boat.basepart1.turn) elseif input == "d" and stroke == "release" then boat.stats.turning.Value = false --stopTurn(boat.basepart1.turn) end end end end)
You really only need to focus on the goForward function, since that's what makes the boat move forward. I've got it so that you can turn the boat and it will move in the direction that it's turning, and I also have acceleration and de-acceleration down. However, I just can't seem to figure out a way to make this boat have a max speed. I want it so that the boat cannot go over a certain speed. Can anyone help me out?
Set your own maximum speed, rather than setting Positive Infinity as maximum speed .
--Line 08 move.MaxForce = Vector3.new(UR MAXIMUM SPEED,0,UR MAXIMUM SPEED)