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.