My gui isnt working

i tried to make a simple open and close gui script and for some reason just does not work at all

local player = game.Players.LocalPlayer
local button = script.Parent
panel = button.AdminPanel

while wait() do
	if player.Name == "woloexe" then
		button.Visible = true
		
		function onButtonPressed()
			if panel.Visible == false then
				panel.Visible = true
			end
		end
	else
		button.Visible = false
		panel.Visible = false
	end
end

button.MouseButton1Click:Connect(onButtonPressed)
1 Like

You dont need the while wait() do part because MouseButton1Click is always listening for a click

2 Likes

I’m not quite sure what isn’t working about it. I am pretty much taking a stab in the dark guessing that it’s showing up, but not disappearing from the code but you expect it to toggle. Though I’m unsure as to what the problem you have with it is, so if I guessed wrong please clarify what’s not working about your code. Here is what I would change to the code that will make it cleaner and, if my guess was correct, fix the issue.

local player = game.Players.LocalPlayer
local button = script.Parent
panel = button.AdminPanel

--Removed the while loop because it was running code repetitively that will only do something the first time, latter iterations it would just tell values to be set to what they already are making the loop pointless.
if player.Name == "woloexe" then
	button.Visible = true
else
	button.Visible = false
	panel.Visible = false
end

function onButtonPressed()
	panel.Visible = not panel.Visible --This just toggles whether panel is visible or not, if my guess of what was broken is correct, this is the change that fixes your code.  Originally you only had it show the panel, but never make it hide it.
end
button.MouseButton1Click:Connect(onButtonPressed)
2 Likes

it works! thank you so much for the help!