Only one button for one ScreenGUI works

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    For the Buttons to open their respective GUIs

  2. What is the issue? Include screenshots / videos if possible!
    My different buttons for opening different ScreenGUIs only open one ScreenGUI despite using the same code for each button

image

NOTE: I’ve already modified the scripts to fit with their respective parents/variables

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Yes I have, but non seem to solve my problem.

This is the code I’ve used for the buttons.
FOR THE SETTINGS (The one that works)

local frame = player.PlayerGui.SettingsUI.Main
local sound = script.Sound

script.Parent.Activated:Connect(function(settings)

	frame.Visible = not frame.Visible
	sound:Play()
	
end)

FOR THE SHOP (DOESN’T WORK)

local frame = player.PlayerGui.ShopUI.Main
local sound = script.Sound

script.Parent.Activated:Connect(function(settings)

	frame.Visible = not frame.Visible
	sound:Play()
	
end)

The output looks like this:

I’ve been working on this bug for about 2 hours now, I’m also quite new to scripting. I’ll appreciate the help and feedback alot! Thank you!

change it to .MouseButton1Click

also please make sure the localscript is parented under the one that doesnt work

Hello! The LocalScript is already parented under the button that doesn’t work
image
and I’ve already tried switching around .MouseButton1Click and .Activated, both have the same outcome. The other UI still won’t open.

according to your output the script errors on line 2

are you sure the sound exists inside localscript?

Output indicates the problem lies in line 2. That’s where your sound path is declared. Essentially there is nothing wrong with the code, and .Activated is proper. What could be the cause is that the sound is not yet copied at the time script looks for it. When player joins, player.PlayerGui is created and UI components are copied from StarterGui into it. That’s why we always use :WaitForChild("name_here") when working with GUIs and accessing anything script is not parented to.

2 Likes

Yes it does, and my bad. Line 2 actually contains this variable:

local frame = player.PlayerGui.ShopUI.Main

and yes, I’ve defined the variable ‘player’ in Line 1 I just forgot to add it to the main post.

(DOESNT WORK)

local player = game.Players.LocalPlayer
local frame = player.PlayerGui.ShopUI.Main
local sound = script.Sound

script.Parent.Activated:Connect(function(shop)

	frame.Visible = not frame.Visible
	sound:Play()

end)

(WORKS)

local player = game.Players.LocalPlayer
local frame = player.PlayerGui.SettingsUI.Main
local sound = script.Sound

script.Parent.Activated:Connect(function(settings)

	frame.Visible = not frame.Visible
	sound:Play()
	
end)

in that case

local frame = player.PlayerGui:WaitForChild("ShopUI"):WaitForChild("Main")
1 Like

and also please provide us with the full error message so we can know whats going on

Thank you! And I apologize, it was my first time using the forums and this was my first post so I was still getting used to the formatting.

Thank you! :WaitForChild worked, and now the GUI has appeared. I can’t believe this took me 3 whole hours, the solution was so simple. :smiling_face_with_tear: I appreciate the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.