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

Why won't the shop open when I press x?

Alright so I made a Key Pressing Script using UserInputService.

local UIS = game:GetService('UserInputService')
local player = game.Players.LocalPlayer
local shop = script.Parent.Parent:WaitForChild('PlayerGui').ShopGui

UIS.InputBegan:connect(function(InputObject)
	if InputObject.KeyCode == Enum.KeyCode.X then
		
		shop.Background.Visible = true
		print('X was pressed')
	end
end)


1 answer

✓ Accepted answer

Quick fix I found to your problem.

local UIS = game:GetService('UserInputService')
local player = game.Players.LocalPlayer

UIS.InputBegan:connect(function(InputObject)
	local shop = script.Parent.Parent:WaitForChild('PlayerGui').ShopGui
    if InputObject.KeyCode == Enum.KeyCode.X then
        shop.Background.Visible = true
        print('X was pressed')
    end
end)

I moved the shop variable into the InputBegan function so it checks it once you have clicked a key.

If this helped make sure to Accept the Answer

1 comment

0

Why does this make it work? Is it because he was looking for the shop before it was loaded?

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