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

What is wrong? Having an issue with guis not turning visible/invisible in game

Asked by 5 years ago
Edited 5 years ago

So, I am having an issue with guis not turning visible/invisible in game. I have a keybind event that looks like this

local gui = game:GetService("StarterGui")
local shop = gui.shopgui.Frame -- The name of the shop frame
local mouse = game.Players:GetMouse()
local toggle = false

mouse.KeyDown:Connect(function(key)
    if key == "m" then
        if toggle == false then
        shop.Visible = true
        toggle = true
   elseif toggle == true then
        shop.Visible = false
        toggle = false
      end
     end
    end
end)

Although, while im in studio and playing the game I can see the property of the gui and it says its visible but it doesn't show in the game screen. Help would be appreciated. Ask any questions about this if you have trouble understanding.

2 answers

Log in to vote
0
Answered by
danglt 185
5 years ago
local gui = game:GetService("StarterGui")
local shop = gui.shopgui.Frame -- The name of the shop frame
local mouse = game.Players:GetMouse()
local toggle = false

mouse.KeyDown:Connect(function(key)
    if key == "m" then
        if toggle == false then
        shop.Visible = true
   elseif toggle == true then
        shop.Visible = false
      end
     end
    end
end)

Try This without the toggle = true & toggle = false

0
finally got this accepted after 2 months lol danglt 185 — 5y
Ad
Log in to vote
1
Answered by
metryy 306 Moderation Voter
5 years ago

Use the InputBegan event in UserInputService instead of the KeyDown event.

local UIS = game:GetService("UserInputService")
local shop = script.Parent -- Put this script in the GUI 
local toggle

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.M then -- checks if the key that fired the event was "M"
        if toggle then -- checks if the debounce is true 
            shop.Visible = false -- if true then sets the visibility to false and db to false
            toggle = false
        else
            shop.Visible = true -- if false then sets the visibility to true and db to true 
            toggle = true
        end
    end
end)

Answer this question