I recoment using body force as the moving force and body velocity as a drag force so it stays at a constant speed, try setting the velocity of the body velocity to negative of the spaceship’s velocity
local Part = ??? --the main part where bodyvelocity is exerted
Part.AssemblyLinearVelocity += Part.CFrame.RightVector*(0-((Part.CFrame:VectorToObjectSpace(Part.AssemblyLinearVelocity).X)))
Even though I don’t think this would fix your problem, here are some code improvements you could make for efficiency.
Also, your BodyForce is applied on the server, so you should be using something on the server to determine the ship’s direction. I think using the HumanoidRootPart’s CFrame is OK 99% of the time, but just in case there is latency on the client or an exploit attempt, I would use something on the server instead just in case. Maybe this is interfering with your direction due to latency somehow?
local acceleration = script.Parent.Parent.Acceleration.Value * 1000
script.Parent.Parent.Thrust.MaxForce = Vector3.new(acceleration, acceleration, acceleration)
local IdleVelocity = Vector3.New(0, 0, 0)
local seat = -- your path to the seat/VehicleSeat
local ThrustOn = script.Parent.Parent.Thrust.On
-- Only make changes when you know the value has changed. No need to check it every render.
ThrustOn.Changed:Connect(function(newValue)
if newValue then
script.Parent.Parent.Thrust.Velocity = seat.LookVector * script.Parent.Parent.TopSpeed.Value
else
script.Parent.Parent.Thrust.Velocity = IdleVelocity
end
end)
-- Instead if having two remote events for on and off, just put it in the same one, telling you whether the player wants the thrust on or off
script.Parent.OnServerEvent:Connect(function(plr, thrust)
script.Parent.Parent.Thrust.On.Value = thrust
end)
I haven’t checked this code for errors and you need to put in your own path to the seat, but that should help make things more efficient, more readable for you, and hopefully easier to debug.