How to make a close button for UI?

I have some slider UI designed with a close button(I only left in code relevant to the close button):

CloseUIButton : button_loud = button_loud{DefaultText := CloseText}
CloseUIButton.OnClick().Subscribe(ClosePressed)


overlay_slot:   # Close Button
                    Widget := CloseUIButton
                    HorizontalAlignment := horizontal_alignment.Center
                    VerticalAlignment := vertical_alignment.Bottom
                    Padding := margin{Left:=0.0,Top:=0.0,Right:=0.0,Bottom:=375.0}


ClosePressed(Message:widget_message):void =
         if (PlayerUI:player_ui = GetPlayerUI[Message.Player], MyUI: overlay = MyMap[Message.Player]?, SelectedButton: text_button_base = text_button_base[Message.Source]):
               PlayerUI.RemoveWidget(MyUI)
              if (MyMap[Message.Player] = false) {}

My problem is that the close button is quite inconsistent and when pressed it will occasionally, with no pattern from what I can tell, remove the slider UI but not any of the buttons(the close button and 2 others I have on the UI). Is this a UEFN issue with play sessions being inconsistent or is my code flawed? If my code is flawed, what way could I fix it?

I found this video helpful.