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

[SOLVED] Pressing the A Button does nothing?

Asked by 5 years ago
Edited 4 years ago
local label = script.Parent
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local GuiService = game:GetService("GuiService")

label.TextScaled = GuiService:IsTenFootInterface()

function button()
    if UserInputService.GamepadEnabled == true then
        label.Text = "Press A"
    else
        label.Text = "Press Enter"
    end
end

function startGame()
    local menuFrame = label.Parent:FindFirstChild("MenuFrame")

    if menuFrame ~= nil then
        ContextActionService:UnbindAction("StartGame")
        menuFrame.Visible = true
        label:Destroy()
    end
end

function pressEnter(actionName, inputState, inputObj)
    if inputState == Enum.UserInputState.Begin then
        startGame()
    end
end

ContextActionService:BindAction("StartGame", pressEnter, false, Enum.KeyCode.Return, Enum.KeyCode.ButtonA)

button()

UserInputService.GamepadConnected:Connect(function()
    button()
end)

UserInputService.GamepadDisconnected:Connect(function()
    button()
end)

while true do
    label.TextTransparency = 0
    wait(0.25)
    label.TextTransparency = 1
    wait(0.25)
end

Even though pressEnter() is bound to both the Enter key on a keyboard and the A Button on a gamepad, nothing happens when I press A.

Is there a way to fix this?

0
instead of doing Enum.KeyCode.ButtonA try doing Enum.KeyCode.A HappyTimIsHim 652 — 5y
0
Are you using this in Server Script? this works in Local Script. yHasteeD 1819 — 5y
0
OOOOOOOOOOOOF!!!!! you are putting a loop at lines 44 - 49, you do realize once a loop starts it cannot end unless you use break, right? Basically any touch event, anything like that will clearly not work until the loop ends. greatneil80 2647 — 5y
0
Does that affect BindAction too? BrockRocksYourSocks 48 — 5y
View all comments (2 more)
0
@HappyTimIsHim he is using a gamepad not a keyboard. "Enum.KeyCode.A" is for keyboards. DeceptiveCaster 3761 — 5y
0
@greatneil80 i agree. Doing that would trigger an epileptic seizure. DeceptiveCaster 3761 — 5y

Answer this question