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 6 years ago
Edited 6 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

01local gui = game:GetService("StarterGui")
02local shop = gui.shopgui.Frame -- The name of the shop frame
03local mouse = game.Players:GetMouse()
04local toggle = false
05 
06mouse.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
17end)

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
6 years ago
01local gui = game:GetService("StarterGui")
02local shop = gui.shopgui.Frame -- The name of the shop frame
03local mouse = game.Players:GetMouse()
04local toggle = false
05 
06mouse.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
15end)

Try This without the toggle = true & toggle = false

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

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

01local UIS = game:GetService("UserInputService")
02local shop = script.Parent -- Put this script in the GUI
03local toggle
04 
05UIS.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
15end)

Answer this question