Frame isnt becoming invisible

Hi all! Im trying to create a button where if you click it, Another frame becomes visible, And another becomes invisible, Sadly for some reason its not working.

Apps = script.Parent.Parent.Parent.Apps
SocialMedia = script.Parent.Parent.Parent.Parent.SocialMedia

script.Parent.MouseButton1Click:Connect(function(LeftClick)
	SocialMedia.Visible = true
	
	if SocialMedia.Visible == true then
		Apps.Visible = false
	end
	
end)

Dont judge, I had a coding break for like a year and Im basically blank.

Your code is correct, try verifying that:

  • The script is a LocalScript
  • Your paths are correct (Apps and SocialMedia index to the correct places)
  • The button is actually being clicked (add a print() underneath the connection

On an unrelated note i’d also recommend using Activated instead of MouseButton1Click - it does the same thing however Activated fires for all platforms

currently getting, SocialMedia is not a valid member of PlayerGui “Players.westyboy08.PlayerGui” - Client - LocalScript:2

Try doing:

SocialMedia = script.Parent.Parent.Parent.Parent:WaitForChild("SocialMedia")

This will instead wait for the frame to load and not directly try to index the frame.

Can you send a picture of the gui, with all it’s children in the explorer?

Apps = script.Parent.Parent.Parent.Apps
SocialMedia = script.Parent.Parent.Parent.Parent.SocialMedia
SocialMedia.Visible = true

script.Parent.MouseButton1Click:Connect(function(player)
if SocialMedia.Visible == true then
Apps.Visible = false
end

end)

If that doesn’t work make sure you referenced the frame you want to make invisible and the the frame you want to become visible correctly.

Sadly, Its when I press a button, I want to show SocialMedia. But in your code It Shows socialmedia when button isnt clicked, Hence the reason why is was bellow MouseButton1Click.

I want to open SocialMedia when I click the button (In screen gui).
I want to close Apps (In screen gui) When I click.

Try removing the final .Parent before .SocialMedia. To me, it looks like you just have too many .Parent’s.

Basically this: SocialMedia = script.Parent.Parent.Parent.SocialMedia

Done, Still nothing :frowning: Hate scripts I cant fix

Did it output an error? If so, can you send what it said?

It used to say SocialMedia is not a valid member of PlayerGui “Players.westyboy08.PlayerGui” - Client - LocalScript:2, But @iFrexsim Fixed it with, WaitForChild(“SocialMedia”), But it still dosen’t Work. When I click it nothing happens

This might be a bit of a bad idea, but, try removing the WaitForChild and just see what happens.

2 Likes

Thank the lords of heaven above! (Jokes) It finally works!

Well…I’m surprised. Guess that did the trick, huh.

2 Likes