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
01function 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 = UDim2.new(stallLine,0,0,0)
View all 59 lines...

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.

1function Function()
2    game.workspace.BoolValue.Value = true --Make it so this boolean allows you to thrust
3 
4mouse.KeyDown:connect(function(key)
5    key = key:lower()
6    if key == "t" then
7        Function()
8    end
9end)

and then code the speed to change.

1if game.workspace.BoolValue.Value == true then
2 
3    -- code it to change the speed of the plane
4 
5end

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.

01function yourcodehere()
02 
03end
04 
05game:GetService('ContextActionService'):BindAction(
06    "CodeHere",
07    yourcodehere,
08    false,
09    Enum.KeyCode.T
10)

Answer this question