01 | function fly(m) -- Main function that controls all of the flying stuff. Very messy. |
02 | flying = true |
03 | local pos,t = main.Position,time() |
04 | local lastStall = false |
05 | while ((flying) and ( not dead)) do |
06 | realSpeed = ((pos-main.Position).magnitude/(time()-t)) -- Calculate "real" speed |
07 | pos,t = main.Position,time() |
08 | local max = (maxSpeed+(-main.CFrame.lookVector.y*speedVary)) -- Speed variety based on the pitch of the aircraft |
09 | desiredSpeed = (max*(on and throttle or 0 )) -- Find speed based on throttle |
10 | local change = (desiredSpeed > currentSpeed and 1 or - 1 ) -- Decide between accelerating or decelerating |
11 | currentSpeed = (currentSpeed+(accel*change)) -- Calculate new speed |
12 | -- local throttleNeeded = |
13 | local stallLine = ((stallSpeed/math.floor(currentSpeed+ 0.5 ))*(stallSpeed/max)) |
14 | stallLine = (stallLine > 1 and 1 or stallLine) |
15 | panel.Throttle.Bar.StallLine.Position = UDim 2. new(stallLine, 0 , 0 , 0 ) |
I'd suggest making a LocalScript in StarterPlayerScripts that toggles a BoolValue that is in the workspace. Insert one into it and then script the speed of the plane to change if the boolean is true.
This script just for the letter pressed, not the speed changing.
1 | function Function() |
2 | game.workspace.BoolValue.Value = true --Make it so this boolean allows you to thrust |
3 |
4 | mouse.KeyDown:connect( function (key) |
5 | key = key:lower() |
6 | if key = = "t" then |
7 | Function() |
8 | end |
9 | end ) |
and then code the speed to change.
1 | if game.workspace.BoolValue.Value = = true then |
2 |
3 | -- code it to change the speed of the plane |
4 |
5 | end |
Hope this helps.
Bind your function using the BindAction
method of the ContextActionService
. Also, don’t use ChurroRX’s method of KeyDown
, as it is deprecated.
01 | function yourcodehere() |
02 |
03 | end |
04 |
05 | game:GetService( 'ContextActionService' ):BindAction( |
06 | "CodeHere" , |
07 | yourcodehere, |
08 | false , |
09 | Enum.KeyCode.T |
10 | ) |