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

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

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
3
Answered by 7 years ago

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

0
Why does this make it work? Is it because he was looking for the shop before it was loaded? Vezious 310 — 7y
Ad

Answer this question