Better way of coding this?

Hello all, I have a code that seems pretty bad to me. I’d like to know if there is any better way of doing this.

What happens here is that when a player challenges another player, this “request” should automatically be cancelled after 20 seconds.
I am pretty new in this and I am thinking if there is a better/easier way of coding something like this, maybe even creating a separate blueprint for it.

It’s generally better to calculate the time at which the request should be canceled, rather than try to decrement a value.
You can then calculate “time until cancel” by doing “TimeOfExpiry - CurrentTime” if you need to display it.
You can then go two ways:

  1. In Event Tick, check whether “current time” is greater than “time of expiry,” and if so, cancel the request
  2. Set a timer when you issue the request, set for 20 seconds, and if the request is accepted, cancel that timer, else when the timer expires, cancel the request

Finally, you want to run this set of requests only on the server, and use replication to get the information to the cilents, because client clocks will not be 100% in sync with the server.

Thanks for the tips!