Issue with helicopter script

Hello,

So I am using a spawner to spawn a helicopter, which has this code in a localscript, giving it its main functions:

local ContextActionService = game:GetService("ContextActionService")
if script.HeliSeat.Value == nil then
	script.Parent:Destroy()
	error("HeliSeatL")
end
local DragFactor = 30
local HeliSeat = script.HeliSeat.Value
local Force = HeliSeat.VectorForce
local BG = HeliSeat.BodyGyro
local TotalMass = HeliSeat.AssemblyMass
local MaxForceY = (TotalMass * game.Workspace.Gravity)*1.1
local StableForceY = (TotalMass * game.Workspace.Gravity)
local MaxForceZ = (TotalMass * game.Workspace.Gravity)*0.6
local RotorSpeed = 100000
local RotorSpeedThrottle = 100000
function cleanUp()
ContextActionService:UnbindAction("RotorSpeedUp")
ContextActionService:UnbindAction("RotorSpeedDown")
script.Parent:Destroy()
end
function UpdateStep(delta)
local drag = -HeliSeat.Velocity*DragFactor
drag = drag * drag
drag = Vector3.new(math.sign(-HeliSeat.Velocity.X)*drag.X,math.sign(-HeliSeat.Velocity.Y)*drag.Y,math.sign(-HeliSeat.Velocity.Z)*drag.Z)
	local UpwardsForce = Vector3.new(0,RotorSpeed,0)
local ForwardsForce = HeliSeat.Throttle*MaxForceZ * HeliSeat.CFrame.LookVector
Force.Force = UpwardsForce + ForwardsForce + drag
HeliSeat.AssemblyAngularVelocity = Vector3.new(0,-HeliSeat.Steer/1,0)
end
spawn(function()
	while HeliSeat and HeliSeat.Occupant == game.Players.LocalPlayer.Character.Humanoid do
	local delta = wait()
	UpdateStep(delta)
	end
	cleanUp()
end)

local function handleAction(actionName, inputState, inputObject)
	if actionName == "RotorSpeedUp" then
		if inputState == Enum.UserInputState.Begin then
			RotorSpeed = MaxForceY
		else
			RotorSpeed = StableForceY
		end
	elseif actionName == "RotorSpeedDown" then
		if inputState == Enum.UserInputState.Begin then
			RotorSpeed = MaxForceY * 0.04
		else
			RotorSpeed = StableForceY
		end
	end
end
ContextActionService:BindAction("RotorSpeedUp", handleAction, true, Enum.KeyCode.E, Enum.KeyCode.ButtonR1)
ContextActionService:SetImage("RotorSpeedUp","rbxassetid://29563813")
ContextActionService:SetPosition("RotorSpeedUp",UDim2.new(0.25, 0,0.3, 0))
ContextActionService:BindAction("RotorSpeedDown", handleAction, true, Enum.KeyCode.Q, Enum.KeyCode.ButtonL1)
ContextActionService:SetImage("RotorSpeedDown","rbxassetid://29563831")
ContextActionService:SetPosition("RotorSpeedDown",UDim2.new(0.25, 0,0.6, 0))
function isMobile()
	local mobileBool = game.ReplicatedStorage:FindFirstChild("IsMobile")
	if mobileBool then
		return true
	else
		return false
	end
end

if isMobile() then
end

The issue arises when the helicopter is first spawned; upon sitting for the very first time, the helicopter does not elevate when pressing the relevant inputs. If i leave the seat, then sit in it again. it works. If i respawn the helicopter, it also works. The keybinds register correctly, the error seems to have something to do with the VectorForce but I tried everything.

Thank you to anybody who can help, I would be indebted to anybody who would help solve this issue.

Since this seems to be a local script with local physics (Context action service).

Then im assuming the problem is network ownership which thr client needs to have in order to apply force to the helicopter. You should double check for this assumption/theory.

1 Like

I checked everything regarding the serverscript for networkownership, and it works proprely.

I noticed that the helicopter’s AssemblyLinearVelocity when first spawning and sitting in it ranges from -0.001 to -0, preventing the helicopter from taking off. When I stand up and sit back down, without doing anything AssemblyLinearVelocity is stable at 0. Any clue on what is causing this?

Fixed, turns out a skin/wrap for the helicopter that changed the material to metal also changed the total mass :skull:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.