Help fix my script

hello everyone, I created a script when you press the button, it closes the icons, but it works for me when I press it, it closes and when I press it again, it does not open my script

 local visible = game.StarterGui.GamepassShop.Parent.CodeGui
  script.Parent.MouseButton1Click:Connect(function()
if visible then 
  script.Parent.Parent.Parent.GamepassShop["Open/Close"].Visible = false
	script.Parent.Parent.Parent.CodeGui["Open/Close"].Visible = false	
	script.Parent.Text = "<<<"
else
	script.Parent.Parent.Parent.GamepassShop["Open/Close"].Visible = true
	script.Parent.Parent.Parent.CodeGui["Open/Close"].Visible = true
	script.Parent.Text = ">>>"
	
 end
 end)
2 Likes

Is this what you meant to do on the first line? (You forgot .Visible)
local visible = game.StarterGui.GamepassShop.Parent.CodeGui → .Visible
(Considering that if “CodeGui” is a frame.)

1 Like

I redid the script ter it looks like this

local visible = 
 game.StarterGui.GamepassShop["Open/Close"].Parent.Parent.CodeGui["Open/Close"]
 script.Parent.MouseButton1Click:Connect(function()
if visible then 
	script.Parent.Parent.Parent.GamepassShop["Open/Close"].Visible = false
	script.Parent.Parent.Parent.CodeGui["Open/Close"].Visible = false	
	script.Parent.Text = "<<<"
 else
	script.Parent.Parent.Parent.GamepassShop["Open/Close"].Visible = true
	script.Parent.Parent.Parent.CodeGui["Open/Close"].Visible = true
	script.Parent.Text = ">>>"

end

end)

1 Like

I think I spotted the problem, so when you close it, it doesn’t re-open it? I believe it’s because you’re getting the Ui that’s currently in starter GUI not in the person’s player GUI.

game.StarterGui.GamepassShop → game.Players.[PlayerName].GamepassShop

You can just give the script I’m very tired of thinking

you’re linking the visible variable in the game StarterGui and not locally in the player’s gui.
try doing some thing like this:

local visible = script.Parent.Parent --this is just an example how to put it locally

game.Players.PlayerAdded:Connect(function(Player)
local visible = game.Players[Player.Name].PlayerGui.GamepassShop["Open/Close"].Parent.Parent.CodeGui["Open/Close"]

-- [[ I don't know the parents of each file, so you're gonna have to edit from here on your own, sincerely sorry. ]] --
--------------------------------------------------------------------------------------------------------------------------------------

 script.Parent.MouseButton1Click:Connect(function()
if visible then 
	script.Parent.Parent.Parent.GamepassShop["Open/Close"].Visible = false
	script.Parent.Parent.Parent.CodeGui["Open/Close"].Visible = false	
	script.Parent.Text = "<<<"
 else
	script.Parent.Parent.Parent.GamepassShop["Open/Close"].Visible = true
	script.Parent.Parent.Parent.CodeGui["Open/Close"].Visible = true
	script.Parent.Text = ">>>"

end

end)

end)
1 Like

not working the script i try in studio

There may be these issues that may cause the script not to work.

  • What’s the parent of the script?
  • Where is it placed?
  • Is it saying any error?

Oh! Found the issue!

Okay so,

game.Players.PlayerAdded:Connect(function() —> game.Players.PlayerAdded:Connect(function(Player) 

it doesn’t work, I press the button, it doesn’t even give an error

Refer to the list I gave you, see if there’s any errors in the console output, and what is it parented to.

so you’re giving up, are you leaving me alone with this script?

I don’t really know how the UI looks and how it is made, sorry that I’m a bit annoying, but may you send a screenshot of the UI? (NOT THE UI ITSELF, BUT IN THE EXPLORER), and where the script is placed inside, so therefore I cannot do more than give you the fix to the code, although I never said I’ll leave without attempting atleast to solve the problem.

Screenshot_1

Screenshot_2

The UI where the script is placed inside of.

I’ve thrown you off who are you by the Russian nation?

OH MY DAYS WAIT IM STUPID, I’m sorry… I’m really sorry…

Is the script a localscript?

if so, there’s no need for the playerAdded event, you can just do

local Player = game.Players.LocalPlayer