Sleep not working in my function?

Hello! I’m trying to add time between when my function is healing the player and it is saying “This invocation calls a function that has the ‘suspends’ effect, which is not allowed by its context.” but when I add suspends to it it breaks my call for it in OnBegin I’m not sure what’s wrong with it, thanks!

HealPlayer(Agent : agent) : void =
        for (Number := 0..5):
            Sleep(2.0) # Sleep isn't working here
            if (Player := player[Agent]):
                if (FortniteCharacter : fort_character = Player.GetFortCharacter[]):
                    FortniteCharacter.Heal(10.0)


    SpawnHealingZone()<suspends> : void =
        Sleep(5.0)
        HealZone.Enable()

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        HealZone.AgentEntersEvent.Subscribe(HealPlayer) # When I add suspends to HealPlayer it breaks here
        DamagePlayer()
        SpawnHealingZone()

If you want a quick fix you could create a handler function like this:

HandleAgentEnter( Agent : agent ) : void =
    spawn:
        HealPlayer(Agent)
# Then you can add suspends on HealPlayer
HealPlayer<suspends>(Agent : agent ) : void = 
    ## Heal your player here
OnBegin<override>()<suspends>:void =
     HealZone.AgentEnteresEvent.Subscribe(HandleAgentEnter)
1 Like

That worked! Thank you so much!! :smiley: