Local Script not changing GUI frame visibility

I want to change the visibility of a frame after a remote event is fired.

Even though it prints “true” for gui.Visible, it never shows on the screen, and is also false when going to Players > PlayerName > And into the gui.

local plr = game.Players.LocalPlayer
local gui = plr.PlayerGui:WaitForChild("PublicOrPrivate").Frame


game.ReplicatedStorage.PublicOrPrivate.PickEvent.OnClientEvent:Connect(function()	
	
	gui.Visible	= true
	
	
	for _, choice in pairs(gui:GetChildren()) do
		choice.MouseButton1Click:Connect(function()
			if choice.Name == "Public" then
				game.ReplicatedStorage.PublicOrPrivate.ReturnEvent:FireServer("Public")
			else
				game.ReplicatedStorage.PublicOrPrivate.ReturnEvent:FireServer("Private")
			end
		end)
		
		gui.Visible = false
	end
end)

Any help appreciated!

You have something in the Frame besides buttons, if so, write a condition.
Or the removeEvent call has errors and the script is interrupted.

local plr = game.Players.LocalPlayer
local gui = plr.PlayerGui:WaitForChild("PublicOrPrivate").Frame


game.ReplicatedStorage.PublicOrPrivate.PickEvent.OnClientEvent:Connect(function()	
	
	gui.Visible	= true
	
	
	for _, choice in pairs(gui:GetChildren()) do

        if choice:IsA("TextButton") then

		choice.MouseButton1Click:Connect(function()
			if choice.Name == "Public" then
				game.ReplicatedStorage.PublicOrPrivate.ReturnEvent:FireServer("Public")
			else
				game.ReplicatedStorage.PublicOrPrivate.ReturnEvent:FireServer("Private")
			end
		end)

		end

		gui.Visible = false
	end
end)

I’ve still got the same issue.

the problem is with your logic

 for _, choice in pairs(gui:GetChildren()) do
        choice.MouseButton1Click:Connect(function()
            if choice.Name == "Public" then
                game.ReplicatedStorage.PublicOrPrivate.ReturnEvent:FireServer("Public")
            else
                game.ReplicatedStorage.PublicOrPrivate.ReturnEvent:FireServer("Private")
            end
            
            gui.Visible = false
        end)
    end

Is PublicOrPrivate.Enabled = true?

That worked! And I just see now my previous error… Thanks!