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

How do i make it that i can press the letter X and it will open the shop?

Asked by 4 years ago

Sorry im new to scripting and i just really need help

local Button = script.Parent
Box = script.Parent.Parent.Box

function onClick()
    if Box.Visible == false then
        Box.Visible = true
        Button.Text = "CLOSE"
    elseif Box.Visible == true then
        Box.Visible = false
        Button.Text = "SHOP"
    end
end

Button.MouseButton1Click:connect(onClick)

I didnt attempt to do it yet because i have no idea how, please help

1 answer

Log in to vote
1
Answered by 4 years ago

Try using UIS

local UIS = game:GetService("UserInputService")
local btn = script.Parent

local box = script.Parent.Parent.Box

UIS.InputBegan:Connect(function(input)
    if input.KeyCode = Enum.KeyCode.X then
        if box.Visible == false then
            box.Visible = true
            btn.Text = "Close"
        elseif box.Visible == true then
            box.Visible = false
            button.Text = "Shop"
        end
    end
end

Then put the mousebutton1click code below. Hope this helped!

Ad

Answer this question