Surface Ui button not working[SOLVED]

Hellow fellow devforum users! When the “characters” button is pressed the surface GUI in the “options menu” part doesn’t pop up. I can’t replace the local script with a server script because then the UI will pop up for everyone instead of just the person who clicked it. All help is appreciated!

here is the hierachy
Screenshot 2024-11-09 at 8.23.35 AM

and here is the updated server script

local Event1 = script.Parent.RemoteEvent
local Event2 = script.Parent.RemoteEvent2
local OpenValue = script.Parent.Open.Value

script.Parent.MouseButton1Click:Connect(function(player)
	if OpenValue == false then 
	Event1:FireClient(player)
	OpenValue = true
	else
		Event2:FireClient(player)
	end
end)

here is the local script that interprets the client event

local event = script.Parent.RemoteEvent
local event2 = script.Parent.RemoteEvent2
local Frame = script.Parent.Parent.Parent.Parent.OptionsMenu.SurfaceGui.Frame

event.OnClientEvent:Connect(function()
	Frame.Visible = true
end)

event2.OnClientEvent:Connect(function()
	Frame.Visible = false
end)
1 Like

I believe that your LocalScript is under the Workspace right? LocalScripts don’t execute under Workspace in any conditions.

LocalScripts can only execute when under either player’s backpack(StarterPack), player’s PlayerGUI(StarterGui), player’s Character(StarterCharacterScripts) or the player’s scripts(StarterPlayerScripts).

2 Likes

Oh…. Welp that’s embarrassing lol. I’ll test it out, see if it works, thanks for the help!

2 Likes

You can achieve your goal using only LocalScript without remote events and server script.

Create a LocalScript and place it either in StarterGui or in one of the other locations that @proturk_yt has specified and write the following code inside it:

local menu = workspace:WaitForChild("Menu")
local charactersBtn = menu:WaitForChild("Main"):WaitForChild("BtnUI"):WaitForChild("Characters")
local optionsMenuFrame = menu:WaitForChild("OptionsMenu"):WaitForChild("SurfaceGui"):WaitForChild("Frame")
local openValue = charactersBtn:WaitForChild("Open").Value

charactersBtn.MouseButton1Click:Connect(function()
	if openValue == false then
		optionsMenuFrame.Visible = true
		openValue = true
	else
		optionsMenuFrame.Visible = false
		openValue = false
	end
end)

The LocalScript runs separately for each player, and players will not see how other players interact with the UI

2 Likes

Glad I can do it without the server script(harder to edit scripts). Thanks for the help!

2 Likes

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