I need help fixing a Shop Open Gui. For some reason, when I click it, it just doesn't open. Here's my Hierarchy, so you know what's going on: http://gyazo.com/94cd60bd298fe92c8add9c169725d408
And here's my code:
local ScreenGui = game.StarterGui.ScreenGui local Button = script.Parent local ShopBG = ScreenGui.ShopBG function onClick() if ShopBG.Visible == false then ShopBG.Visible = true elseif ShopBG.Visible == true then ShopBG.Visible = false else print("An error has occured with the Shop Opening Script.") end end Button.MouseButton1Click:connect(onClick)
Here is a code that works for me every time.
function die() script.Parent.Parent.ShopBG.Visible = true --This makes it when the open button is clicked, the frame opens. NOTICE: DO NOT PUT THE OPEN BUTTON INSIDE OF THE SHOPBG FRAME! end script.Parent.MouseButton1Down:connect(die)
Hope this helps! Works and tested. Also, put this code IN A REGULAR SCRIPT NOT A LOCAL ONE. If you need more help with this script, view this link: https://docs.google.com/document/d/1SBIkuy-Skuz22IOsqX2tWC45UT9rw0SrXCwlbMMKhf8/edit
You are trying to connect to a button the StarterGui
. This is not the Gui players will receive in game. Put the script in the StarterGui and connect from the script's parents, locally.
Move the script to the StarterGui and replace the first line with the following:
local StarterGui = script.Parent