The script works fine but the frame won't show up

i tried to make a script which would make a frame visible every time you click on a button, but the script works fine and the frame visible is set to true, but the frame won’t show up

local ShopOpen = script.Parent
local Shop = game.StarterGui.ScreenGui.Shop
local ShopOpenBool = false

ShopOpen.MouseButton1Click:Connect(function()
	if ShopOpenBool == false then
		ShopOpenBool = true
		Shop.Visible = true
	elseif ShopOpenBool == true then
		ShopOpenBool = false
		Shop.Visible = false
	end
end)
1 Like

Is the ScreenGui enabled? If not, the script frame will be visible but won’t show.

it is enabled but won’t work, i tried every methods

Your script is fine. Are there any error’s in the output?

there are no errors at all sir

Oh my bad, it needs to be in playergui.

local Shop = game.starterGui.ScreenGui.Shop -- instead
local Shop = game.Players.LocalPlayer.PlayerGui.Screengui.Shop

The problem is on this line -

local Shop = game.StarterGui.ScreenGui.Shop

instead of this, replace it with -

local Shop = script.Parent.Parent.Frame

2 Likes

Hello there,

This should work;

local ShopOpen = script.Parent
local Shop = script.Parent.Parent.Shop

ShopOpen.MouseButton1Click:Connect(function()
	if Shop.Visible == false then
		Shop.Visible = true
	else
		Shop.Visible = false
	end
end)

Kind regards,
DutchBuilds.

1 Like

The problem with the first line is,

When the player is in the game,
‘StarterGui’ for him is ‘PlayerGui’.

Hence, what you could do, is

  1. What I wrote above.
    2)Replace it with -
local ShopOpen = script.Parent
local Player = game.Players.LocalPlayer
local Shop = Player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui"):FindFirstChild("Frame")
local ShopOpenBool = false

ShopOpen.MouseButton1Click:Connect(function()
	if ShopOpenBool == false then
		ShopOpenBool = true
		Shop.Visible = true
	elseif ShopOpenBool == true then
		ShopOpenBool = false
		Shop.Visible = false
	end
end)