So, I am having an issue with guis not turning visible/invisible in game. I have a keybind event that looks like this
01 | local gui = game:GetService( "StarterGui" ) |
02 | local shop = gui.shopgui.Frame -- The name of the shop frame |
03 | local mouse = game.Players:GetMouse() |
04 | local toggle = false |
05 |
06 | mouse.KeyDown:Connect( function (key) |
07 | if key = = "m" then |
08 | if toggle = = false then |
09 | shop.Visible = true |
10 | toggle = true |
11 | elseif toggle = = true then |
12 | shop.Visible = false |
13 | toggle = false |
14 | end |
15 | end |
16 | end |
17 | 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.
01 | local gui = game:GetService( "StarterGui" ) |
02 | local shop = gui.shopgui.Frame -- The name of the shop frame |
03 | local mouse = game.Players:GetMouse() |
04 | local toggle = false |
05 |
06 | mouse.KeyDown:Connect( function (key) |
07 | if key = = "m" then |
08 | if toggle = = false then |
09 | shop.Visible = true |
10 | elseif toggle = = true then |
11 | shop.Visible = false |
12 | end |
13 | end |
14 | end |
15 | end ) |
Try This without the toggle = true & toggle = false
Use the InputBegan event in UserInputService instead of the KeyDown event.
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local shop = script.Parent -- Put this script in the GUI |
03 | local toggle |
04 |
05 | UIS.InputBegan:Connect( function (input) |
06 | if input.KeyCode = = Enum.KeyCode.M then -- checks if the key that fired the event was "M" |
07 | if toggle then -- checks if the debounce is true |
08 | shop.Visible = false -- if true then sets the visibility to false and db to false |
09 | toggle = false |
10 | else |
11 | shop.Visible = true -- if false then sets the visibility to true and db to true |
12 | toggle = true |
13 | end |
14 | end |
15 | end ) |