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

Why is my plane model detecting A and S/W?

Asked by 4 years ago
Edited 4 years ago

So recently, I've spent some time making an airplane. I've scripted it all myself, and made a script called "AControls'. I've deleted the AControls script, since it just timed out my game, but it still senses a click. When I click A, it triggers my WControls script, as well as my SControls script.

WControls script:

script.Parent.Active.Changed:Connect(function(newValue)
    if newValue == true then
        local userinputservice = game:GetService("UserInputService")
        local plane = game.Workspace:FindFirstChild(script.Parent.Plane.Value)
        local keycode = Enum.KeyCode
        local wkey = keycode.W
        local rshiftkey = Enum.KeyCode.RightShift
        local lshiftkey = Enum.KeyCode.LeftShift
        local gkey = keycode.G
        --making functions for w key--
        local function wpress()
            return userinputservice:IsKeyDown(wkey)
        end
        local function wfunction(input, gameProcessedEvent)
            if wpress() then
                if plane.Values.Throttle.Value < 100 then
                        plane.Values.Throttle.Value = plane.Values.Throttle.Value + 10
                        plane.VehicleSeat.Throttle = plane.VehicleSeat.Throttle +10
                        print("changed plane's throttle")
                    end
                else
                    print("throttle value was already 100.  dismissed.")
                end
            end
        --ended wpress function--   
    userinputservice.InputBegan:connect(wfunction)
        --making functions for s key--
    end
end)

SControls script:

script.Parent.Active.Changed:Connect(function(newValue)
    if newValue == true then
        local userinputservice = game:GetService("UserInputService")
        local plane = game.Workspace:FindFirstChild(script.Parent.Plane.Value)
        local keycode = Enum.KeyCode
        local skey = keycode.S
        local rshiftkey = Enum.KeyCode.RightShift
        local lshiftkey = Enum.KeyCode.LeftShift
        local gkey = keycode.G
        --making functions for w key--
        local function spress()
            return userinputservice:IsKeyDown(skey)
        end
        local function sfunction(input, gameProcessedEvent)
            if spress() then
                if plane.Values.Throttle.Value > 0 and plane.Values.Throttle.Value < 101 then
                    plane.Values.Throttle.Value = plane.Values.Throttle.Value - 10
                plane.VehicleSeat.Throttle = plane.VehicleSeat.Throttle - 10
                end
            else
                print("throttle value was already 0. dismissed.")
            end
        end
        userinputservice.InputBegan:connect(sfunction)
        --ended wpress function--   
    end
end)

Thanks! :)

Answer this question