Function doesn't get unsubscribed right

Hello there!
In my code I’m subscribing another function when a player counter device fails counting:

set UnsubscribeRoundStart = option {CheckIf1Player.CountFailsEvent.Subscribe(RoundStart)}

It’s subscribing the RoundStart function:

    RoundStart() : void =
        Print("Round has started")
        StatusPlaying.Show()
        StatusStopped.Hide()
        ChooseRandomSong()
        spawn {ChooseRandomDuration()}
        if (RoundStartFunction := UnsubscribeRoundStart?):
            RoundStartFunction.Cancel()
            set UnsubscribeRoundStart = false

In the last lines it should unsubscribe the function, but it doesn’t for some reason. When calling this function for example a 2nd time it’s doing everything thats included in the function twice. I also have a variable in my code: var UnspawnRoundCheck:?cancelable = false

Anybody have an idea what I’m doing wrong here?
Greetings!

So I see you’re going with a custom round system, I thought about it but it’s too much work :smiley:

For your question, I’m not sure since I’m pretty sure you can’t Subscribe() twice with the same function (not 100% sure though)

If I’m right, then it could be the CountFailsEvent that gets called twice in the same frame, do you have any other device that could trigger the counter another time ?

Hey!
Not really, atleast not that I’m currently aware of-
My solution was to add some booleans & now it’s working properly! :slight_smile:

1 Like