Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I get GamepadEnabled and ContextActionService to work properly?

Hi.

I'm trying to make an ImageLabel visible using GamepadEnabled = true I'm also trying to make it so that if the user presses "Y" on their gamepad, a purchase is triggered.

Promting the purchase via the gamepad only works in Play Solo, not test server. Making the ImageLabel visible does not work. It did however work when I had the function "printFunction" call the same line of code that is now in the GamepadEnabled-block.

-- setup local variables
local buyButton = script.Parent.buyButton
local productId = 19503206

-- when player clicks on buy brick promt him/her to buy a product
buyButton.MouseButton1Click:connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)
end)

if game:GetService("UserInputService").GamepadEnabled then
	print("Gamepad enabled")
	script.Parent.ButtonSymbol.Visible = true
end

local function printFunction(actionName, state, inputObject)
	if state == Enum.UserInputState.Begin then
		game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)
	end
end
 
game:GetService("ContextActionService"):BindActionToInputTypes("PromptPurchase", printFunction, false, "y", Enum.KeyCode.ButtonY)

No erros in Play Solo. Test server:

ButtonSymbol is not a valid member of Frame Script 'Players.Player1.PlayerGui.ParachuteGamePass.Frame.LocalScript', Line 12

I think this is very weird as it clearly is a member: http://prntscr.com/e4wstv

Ideas?

1 answer

A friend of mine helped me figure it out!

Turns out stuff hadn't loaded yet!

Fix:

repeat wait() until script.Parent:FindFirstChild("whateverItsCalled")

This discussion is preserved as it was. New answers, comments, and votes are closed.