When you replace the code in the script “Handler” with the code below, is the behavior of the plane the behavior you want? This is an edited version of the handler script in the place file.
local plane = script.Parent
local VehicleSeat = plane:WaitForChild("VehicleSeat")
local Base = plane:WaitForChild("Base")
local FlyPart = plane:WaitForChild("FlyPart")
--local VectorForce = FlyPart:WaitForChild("VectorForce")
local AngularVelocity = FlyPart:WaitForChild("AngularVelocity")
local Configurations = plane:WaitForChild("Configurations")
local PropellerMotor = script:WaitForChild("PropellerMotor")
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local speed = Configurations.Speed
local maxSpeed = Configurations.MaxSpeed
local isOn = Configurations.IsOn
local turnOnPropellerTween
local turnOffPropellerTween
local turnOnTween
local turnOffTween
local function getModelMass()
local mass = 0
for i,v in ipairs(plane:GetDescendants()) do
if v:IsA("BasePart") then
--mass += v.AssemblyMass
mass += v:GetMass()
end
end
return mass
end
local function turnOnPropeller()
local tweenInfo = TweenInfo.new(6, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
turnOnPropellerTween = TweenService:Create(speed, tweenInfo, {Value = maxSpeed.Value})
turnOnPropellerTween:Play()
end
local function turnOffPropeller()
local tweenInfo = TweenInfo.new(6, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
turnOffPropellerTween = TweenService:Create(speed, tweenInfo, {Value = 0})
turnOffPropellerTween:Play()
end
local function turnOff()
local tweenInfo = TweenInfo.new(4, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
turnOffTween = TweenService:Create(speed, tweenInfo, {Value = 0})
turnOffTween:Play()
end
local function turnOffAllTweens()
if turnOffTween then
turnOffTween:Pause()
turnOffTween = nil
end
if turnOnTween then
turnOnTween:Pause()
turnOnTween = nil
end
if turnOffPropellerTween then
turnOffPropellerTween:Pause()
turnOffPropellerTween = nil
end
if turnOnPropellerTween then
turnOnPropellerTween:Pause()
turnOnPropellerTween = nil
end
end
local function getCurrentHorizontalSpeed()
local currentVelocity = FlyPart.AssemblyLinearVelocity
local horizontalSpeed = Vector2.new(currentVelocity.X, currentVelocity.Z).Magnitude
return horizontalSpeed
end
local attachment = Instance.new("Attachment")
attachment.Name = "LinearVelocityAttachment"
attachment.Parent = FlyPart
local linearVelocity = Instance.new("LinearVelocity")
--linearVelocity.MaxForce = getModelMass() * 10
linearVelocity.LineDirection = Vector3.new(0, 1, 0)
linearVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
linearVelocity.Attachment0 = attachment
linearVelocity.Parent = FlyPart
local function getEngineVelocity()
return FlyPart.CFrame.LookVector * speed.Value
end
local function getHorizontalSpeed()
local velocity = FlyPart.AssemblyLinearVelocity
return Vector2.new(velocity.X, velocity.Z).Magnitude
end
-- If the check was made using the actual speed of the plane (not just its horizontal speed) then
-- fallVelocity could only briefly be -20 because when vertical velocity is -20, the speed of the plane
-- must be at least 20 which is more than 10.
local function getFallVelocity()
local horizontalSpeed = getHorizontalSpeed()
if horizontalSpeed <= 10 then
return -20
elseif horizontalSpeed <= 50 then
return -5
else
return 0
end
end
local function updateLinearVelocity()
if isOn.Value == true then
linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
linearVelocity.VectorVelocity = getEngineVelocity() + Vector3.new(0, getFallVelocity(), 0)
else
linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
linearVelocity.LineDirection = Vector3.new(0, 1, 0)
linearVelocity.LineVelocity = getFallVelocity()
end
linearVelocity.MaxForce = getModelMass() * 1000
end
RunService.Heartbeat:Connect(function(delta)
--[[
if isOn.Value == true then
local mass = getModelMass()
--print((mass * FlyPart.CFrame.LookVector * speed.Value).Magnitude, (FlyPart.CFrame.LookVector * speed.Value).Magnitude)
VectorForce.Force = FlyPart.CFrame.LookVector * speed.Value
end
--]]
attachment.Position = FlyPart.CFrame:Inverse() * FlyPart.AssemblyCenterOfMass
updateLinearVelocity()
end)
speed:GetPropertyChangedSignal("Value"):Connect(function()
PropellerMotor.AngularVelocity = speed.Value
end)
VehicleSeat:GetPropertyChangedSignal("Steer"):Connect(function()
if isOn.Value == true then
AngularVelocity.AngularVelocity = Vector3.new(AngularVelocity.AngularVelocity.X, -1 * VehicleSeat.Steer, AngularVelocity.AngularVelocity.Z)
end
end)
VehicleSeat:GetPropertyChangedSignal("Throttle"):Connect(function()
if isOn.Value == true then
AngularVelocity.AngularVelocity = Vector3.new(1 * VehicleSeat.Throttle, AngularVelocity.AngularVelocity.Y, AngularVelocity.AngularVelocity.Z)
end
end)
script.ChangeSpeed.OnServerEvent:Connect(function(player, text)
if text == "Add" then
speed.Value += 1
elseif text == "Subtract" then
speed.Value -= 1
end
end)
script.TurnOn.OnServerEvent:Connect(function(player, bool)
isOn.Value = bool
AngularVelocity.Enabled = bool
if bool == false then
turnOffAllTweens()
turnOff()
turnOffPropeller()
else
turnOffAllTweens()
turnOnPropeller()
end
end)
if FlyPart.AssemblyLinearVelocity.Magnitude <= 50 then
FlyPart.AssemblyLinearVelocity = Vector3.new(0, -5, 0)
end