Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I made I Plane and When I Press T I want the Speed to Gain +30 Speed ??

Asked by 6 years ago
                function fly(m) -- Main function that controls all of the flying stuff. Very messy.
                    flying = true
                    local pos,t = main.Position,time()
                    local lastStall = false
                    while ((flying) and (not dead)) do
                        realSpeed = ((pos-main.Position).magnitude/(time()-t))  -- Calculate "real" speed
                        pos,t = main.Position,time()
                        local max = (maxSpeed+(-main.CFrame.lookVector.y*speedVary))    -- Speed variety based on the pitch of the aircraft
                        desiredSpeed = (max*(on and throttle or 0)) -- Find speed based on throttle
                        local change = (desiredSpeed > currentSpeed and 1 or -1)    -- Decide between accelerating or decelerating
                        currentSpeed = (currentSpeed+(accel*change))    -- Calculate new speed
                --      local throttleNeeded = 
                        local stallLine = ((stallSpeed/math.floor(currentSpeed+0.5))*(stallSpeed/max))
                        stallLine = (stallLine > 1 and 1 or stallLine)
                        panel.Throttle.Bar.StallLine.Position = UDim2.new(stallLine,0,0,0)
                        panel.Throttle.Bar.StallLine.BackgroundColor3 = (stallLine > panel.Throttle.Bar.Amount.Size.X.Scale and Color3.new(1,0,0) or Color3.new(0,0,0))
                        if (change == 1) then
                            currentSpeed = (currentSpeed > desiredSpeed and desiredSpeed or currentSpeed)   -- Reduce "glitchy" speed
                        else
                            currentSpeed = (currentSpeed < desiredSpeed and desiredSpeed or currentSpeed)
                        end
                        local tax,stl = taxi(),stall()
                        if ((lastStall) and (not stl) and (not tax)) then   -- Recovering from a stall:
                            if ((realSpeed > -10000) and (realSpeed < 10000)) then
                                currentSpeed = realSpeed
                            else
                                currentSpeed = (stallSpeed+1)
                            end
                        end
                        lastStall = stl
                        move.velocity = (main.CFrame.lookVector*currentSpeed)       -- Set speed to aircraft
                        local bank = ((((m.ViewSizeX/2)-m.X)/(m.ViewSizeX/2))*maxBank)  -- My special equation to calculate the banking of the plane. It's pretty simple actually
                        bank = (bank < -maxBank and -maxBank or bank > maxBank and maxBank or bank)
                        if (tax) then
                            if (currentSpeed < 2) then  -- Stop plane from moving/turning when idled on ground
                                move.maxForce = Vector3.new(0,0,0)
                                gyro.maxTorque = Vector3.new(0,0,0)
                            else
                                move.maxForce = Vector3.new(math.huge,0,math.huge)  -- Taxi
                                gyro.maxTorque = Vector3.new(0,math.huge,0)
                                gyro.cframe = CFrame.new(main.Position,m.Hit.p)
                            end
                        elseif (stl) then
                            move.maxForce = Vector3.new(0,0,0)  -- Stall
                            gyro.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
                            gyro.cframe = (m.Hit*CFrame.Angles(0,0,math.rad(bank)))
                        else
                            move.maxForce = Vector3.new(math.huge,math.huge,math.huge)  -- Fly
                            gyro.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
                            gyro.cframe = (m.Hit*CFrame.Angles(0,0,math.rad(bank)))
                        end
                        if ((altRestrict) and (main.Position.y < altMin)) then  -- If you have altitude restrictions and are below the minimun altitude, then make the plane explode
                            plane.AutoCrash.Value = true
                        end
                        updateGui(tax,stl)  -- Keep the pilot informed!
                        main.Throttle.Value = throttle 
                        wait()
                    end
                end

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

function Function()
    game.workspace.BoolValue.Value = true --Make it so this boolean allows you to thrust

mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "t" then
        Function()
    end
end)

and then code the speed to change.

if game.workspace.BoolValue.Value == true then

    -- code it to change the speed of the plane

end

Hope this helps.

0
KeyDown is deprecated. Please go learn how to script correctly. And on line 5, you’re overriding the key parameter. User#19524 175 — 6y
0
My apologizes. I'm still a beginner in scripting, I was just trying to help. ChurroRX 15 — 6y
0
Beginners wouldn’t use deprecated code. User#19524 175 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Bind your function using the BindAction method of the ContextActionService. Also, don’t use ChurroRX’s method of KeyDown, as it is deprecated.

function yourcodehere()

end

game:GetService('ContextActionService'):BindAction(
    "CodeHere",
    yourcodehere,
    false,
    Enum.KeyCode.T
)

Answer this question