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?

6 comments

0

instead of doing Enum.KeyCode.ButtonA try doing Enum.KeyCode.A

0

Are you using this in Server Script? this works in Local Script.

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.

0

Does that affect BindAction too?

0

@HappyTimIsHim he is using a gamepad not a keyboard. "Enum.KeyCode.A" is for keyboards.

0

@greatneil80 i agree. Doing that would trigger an epileptic seizure.