You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
For the Buttons to open their respective GUIs
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
NOTE: I’ve already modified the scripts to fit with their respective parents/variables
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)
Hello! The LocalScript is already parented under the button that doesn’t work
and I’ve already tried switching around .MouseButton1Click and .Activated, both have the same outcome. The other UI still won’t open.
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.
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)
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. I appreciate the help!