Greetings! So, my friend is scripting a game. He’s stuck on the part of the script where he was trying to get the script to open the music UI, but is stuck on what to do. He made it a LocalScript, which I’ll show a screenshot below, along with the code. So, what is exactly the problem with the code?
Outcome: He tried to open the UI but couldn’t.
Feedback will be great!
local StarterGui = game.StarterGui
local Menu = script.Parent.Background
local CloseButton = Menu.Frame.CloseButton
local MusicMenuButton = StarterGui.SideUI.MusicMenuButton
local MenuOpen = false
MusicMenuButton.MouseButton1Click:Connect(function()
if MenuOpen == true then
Menu.Visible = false
MenuOpen = false
else
Menu.Visible = true
MenuOpen = true
end
end)
CloseButton.MouseButton1Click:Connect(function()
MenuOpen = false
Menu.Visible = true
end)
So, what you’re actually getting is the Server’s own GUI
Whenever you reference the StarterGui, the changes are actually being replicated across the server’s side, and not your client (Or what you currently see on your screen)
Think of the StarterGui as like a template for what’s gonna be cloned into every Player’s PlayerGui
Since what you’re using is a LocalScript, you could just simply reference the PlayerGui if you’re wanting to access other Gui's on the PlayerGui
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local MusicMenuButton = PlayerGui:WaitForChild("SideUI"):WaitForChild("MusicMenuButton")
local Menu = script.Parent.Background
local CloseButton = Menu.Frame.CloseButton
local MenuOpen = false
MusicMenuButton.MouseButton1Click:Connect(function()
if MenuOpen == true then
Menu.Visible = false
MenuOpen = false
else
Menu.Visible = true
MenuOpen = true
end
end)
CloseButton.MouseButton1Click:Connect(function()
MenuOpen = false
Menu.Visible = true
end)