# UI Button gets activated multiple times?

**URL:** <https://forums.unrealengine.com/t/ui-button-gets-activated-multiple-times/1952452>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [July 27, 2024, 4:17pm UTC](https://forums.unrealengine.com/t/ui-button-gets-activated-multiple-times/1952452 "2024-07-27T16:17:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DoomTheDev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DoomTheDev](https://forums.unrealengine.com/u/DoomTheDev)\
**Post date:** [July 27, 2024, 4:17pm UTC](https://forums.unrealengine.com/t/ui-button-gets-activated-multiple-times/1952452/1 "2024-07-27T16:17:39Z")

</div>

Greetings, I have a UI built that works as a shop that has a couple of buttons. All of them work well besides one that simply just runs as many times as it wants. The more time I stay inside the game, the more events it will send once I click it. The other buttons have no issue and work as they should, closing the UI, and opening other tabs. This is incredibly weird and I wasn’t able to find any fix, please help!

```auto
#This is outside at the top of the script:
UpgradeButton : button_loud = button_loud {}
TextForUpgradeWeapon<localizes> : message = "FINISH WEAPON"

#This is in the function that makes the canvas:
UpgradeButton.OnClick().Subscribe(WeaponUpgradeButtonClickEvent)

UpgradeButton.SetText(TextForUpgradeWeapon)

#This is the function that triggers when the button is clicked:
WeaponUpgradeButtonClickEvent(Wdata:widget_message):void=
        Print("Player Pressed UpgradeButton, Start Event") #This gets printed as many times as it wants
        if(Player:=Wdata.Player, PlayerUI:=GetPlayerUI[Player], SelectedButton:=Wdata.Source):
            if(Widgets:=MaybeMyUIPerPlayer[Player]?):
                 Print("Okay") #this too

```

There are no errors btw  
Thank you!

---

<div class="post-metadata">

**Author:** ![DoomTheDev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DoomTheDev](https://forums.unrealengine.com/u/DoomTheDev)\
**Post date:** [July 28, 2024, 2:56pm UTC](https://forums.unrealengine.com/t/ui-button-gets-activated-multiple-times/1952452/2 "2024-07-28T14:56:27Z")

</div>

Bump, I don’t know what I did wrong, please help!

---

<div class="post-metadata">

**Author:** ![Tofuszn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tofuszn/32/1019707_2.png) [@Tofuszn](https://forums.unrealengine.com/u/Tofuszn)\
**Post date:** [March 20, 2025, 1:58am UTC](https://forums.unrealengine.com/t/ui-button-gets-activated-multiple-times/1952452/3 "2025-03-20T01:58:46Z")

</div>

did you ever find a fix to it?

---

<div class="post-metadata">

**Author:** ![Mineblo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mineblo/32/1203575_2.png) [@Mineblo](https://forums.unrealengine.com/u/Mineblo)\
**Post date:** [March 20, 2025, 4:34am UTC](https://forums.unrealengine.com/t/ui-button-gets-activated-multiple-times/1952452/4 "2025-03-20T04:34:07Z")

</div>

@DoomTheDev @Tofuszn The issue was because the `UpgradeButton` was declared globally at the top of the script meaning each time you add it to a player it would always be the same button instead of a new one generated for that player, the problem comes that you are “subscribing” the button clicked event when you attach it to a player `UpgradeButton.OnClick().Subscribe(WeaponUpgradeButtonClickEvent)` And never unsubscribe from it, which means each time you subscribe you are just increasing by one the amount of times the function will be called when the button is pressed, hope that makes sense. If you need a further explanation or questions let me know.

---

<div class="post-metadata">

**Author:** ![Tofuszn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tofuszn/32/1019707_2.png) [@Tofuszn](https://forums.unrealengine.com/u/Tofuszn)\
**Post date:** [March 20, 2025, 5:41am UTC](https://forums.unrealengine.com/t/ui-button-gets-activated-multiple-times/1952452/5 "2025-03-20T05:41:49Z")

</div>

That makes perfect sense! I had my text in a global scope after taking out of a class to experiment with it. I put it back into a class and now it works perfectly 😁 thank you so much!
