How to make code be able to read through loop and go past for other code

here is my current code mostly look at the loop function in the begin class, I want it so the script can go through the loop and look at the code below it and run that too at the same time

using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation }
using { /Verse.org/Simulation/Tags }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/UI }
using { /UnrealEngine.com/Temporary/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }





elimination_game_device := class(creative_device):

    @editable
    EndGameDevice : end_game_device = end_game_device{}

    # Array of item granters used to grant the weapons
    @editable
    var WeaponItemGranters : []item_granter_device = array{}
    
    # This is set later, this will be equal to the the number of weapon item_granters in the island
    var NumberOfEliminationsToWin : int = 0

    # Map container to track players progress. This is how to determine which weapon to award to the player
    var AgentMap : [agent]int = map{}

    #Number of elims
    S2M<localizes>(S:string):message="{S}"
    #var UIButton : button_loud = button_loud{}

    var LastEliminatedBy: [player]player = map{}


    #Checking for new players

    OnPlayerAdded(InPlayer : player) : void =
        if (set AgentMap[InPlayer] = 1) {} 
        AllPlayers := GetPlayspace().GetPlayers()
        for (p:AllPlayers):
            var playerElims : int = 0
            var UIButton : button_loud = button_loud{}
            if (PlayerUI := GetPlayerUI[p]):
                UIButton.SetText(S2M("Kills: {playerElims}"))
                MyCanvas :canvas = canvas:
                    Slots := array:
                        canvas_slot:
                            Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.0}, Maximum := vector2{X := 0.5, Y := 0.0}}
                            Offsets := margin{Top := 100.0, Left := 50.0, Right := 50.0, Bottom := 50.0}
                            Alignment := vector2{X := 0.5, Y := 0.5}
                            SizeToContent := true
                            Widget := UIButton
                PlayerUI.AddWidget(MyCanvas)
            if (p = LastEliminatedBy):
                set playerElims += 1
                UIButton.SetText(S2M("Kills: {playerElims}"))
                
                
                
            
                

    # Check if the victory condition has been met and return the the result
    IsVictoryConditionMet(EliminationNumber:int)<transacts>:logic=
        if:
            EliminationNumber = NumberOfEliminationsToWin
        then:
            return true
        else:
            return false

    #Ending game once player reaches goal
    EndGame(Agent:agent):void=
        EndGameDevice.Activate(Agent)

    # Check if there is a winner for the game, if not then grant the next weapon
    GrantNextWeapon(Agent:agent):void=
        if(Player := player[Agent]):
            if (var CurrentItemNumber:int = AgentMap[Agent]):
                if (IsVictoryConditionMet(CurrentItemNumber) = true):
                    EndGame(Agent) # Game has been won
                else: # Game is not over yet
                    set CurrentItemNumber = CurrentItemNumber + 1
                    if (ItemGranter := WeaponItemGranters[CurrentItemNumber - 1]):
                        Print("Number of Weapon Item Granters: {CurrentItemNumber}")
                        ItemGranter.GrantItem(Agent)
                    
                    if (set AgentMap[Agent] = CurrentItemNumber) {}

    # Event that handles when a player is eliminated
    OnPlayerEliminated(Result:elimination_result):void=
        Eliminator := Result.EliminatingCharacter
        Eliminated := Result.EliminatedCharacter
        if (FortCharacter := Eliminator?, EliminatingAgent := FortCharacter.GetAgent[]):
            if(Eliminator <> Eliminated):
                GrantNextWeapon(EliminatingAgent)
                Print("Granting Weapon")


                

    OnPlayerEliminatedIteration(Result:elimination_result):void=
        Eliminator := Result.EliminatingCharacter
        Eliminated := Result.EliminatedCharacter
        if (FortCharacter := Eliminator?, EliminatingAgent := FortCharacter.GetAgent[]):
            if (Player := player[FortCharacter.GetAgent[]]):
                    Print("Trying To Set Last Eliminated")
                    if:
                        set LastEliminatedBy[Player]
                        
                    
                

    

    #Creating ui kill counter on screen
    #CreateUI(Player : player) : void = 
        #if (PlayerUI := GetPlayerUI[Player]):
            #MyCanvas :canvas = canvas:
                #Slots := array:
                    #canvas_slot:
                        #Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.0}, Maximum := vector2{X := 0.5, Y := 0.0}}
                        #Offsets := margin{Top := 100.0, Left := 50.0, Right := 50.0, Bottom := 50.0}
                        #Alignment := vector2{X := 0.5, Y := 0.5}
                        #SizeToContent := true
                        #Widget := UIButton
            #PlayerUI.AddWidget(MyCanvas)
            

    OnBegin<override>()<suspends>:void=
        Sleep(0.0)
        # Can use this variable to scale the number of eliminations needed based on how many item granters there are in the experience
        set NumberOfEliminationsToWin = WeaponItemGranters.Length
        Print("Number of Weapon Item Granters: {WeaponItemGranters.Length}")
        
        # Randomize the order in which the weapons are granted
        # set WeaponItemGranters = Shuffle(WeaponItemGranters)

        Self.GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)

        # Get all the players in the experience

        AllPlayers := GetPlayspace().GetPlayers()

        for (p:AllPlayers):
            var playerElims : int = 0
            if (fortCharacter := p.GetFortCharacter[]):
                fortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminatedIteration)
            if (PlayerUI := GetPlayerUI[p]):
                var UIButton : button_loud = button_loud{}
                UIButton.SetText(S2M("Kills: {playerElims}"))
                MyCanvas :canvas = canvas:
                    Slots := array:
                        canvas_slot:
                            Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.0}, Maximum := vector2{X := 0.5, Y := 0.0}}
                            Offsets := margin{Top := 100.0, Left := 50.0, Right := 50.0, Bottom := 50.0}
                            Alignment := vector2{X := 0.5, Y := 0.5}
                            SizeToContent := true
                            Widget := UIButton
                PlayerUI.AddWidget(MyCanvas)
                loop:
                    Sleep(0.1)
                    Print("looping")
                if (p = LastEliminatedBy):
                    set playerElims += 1
                    Print("WorkingLoop In If")
                    Print("{playerElims} Please Work, text not updating")
                    UIButton.SetText(S2M("Kills: {playerElims}"))
                else:
                    Print("Broke Loop")
                

        
        for (EliminationGamePlayer : AllPlayers):
            if (FortCharacter := EliminationGamePlayer.GetFortCharacter[]):
                FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) # subscribe to eliminated event
            
            # Add Players to a Map to track progress
            if (set AgentMap[EliminationGamePlayer] = 1) {} 
            
            # Grant the first weapon to each player
            if (FirstItemGranter:item_granter_device = WeaponItemGranters[0]):
                FirstItemGranter.GrantItem(EliminationGamePlayer)
                 

Add break where you want to break the loop.

That is a problem because I am trying to create a kill counter and it needs to be constantly checking, and be able to go past the loop and check the other code

create a void to contain your loop and add when you declare it

MyLoop()<suspends>:void=
    loop:
           loop stuff here

   Sleep(0.5)

to start the loop you use spawn

    OnBegin<override>()<suspends>:void=
        Sleep(0.0)
        Spawn:
                Myloop()

my loop will run along side the main program routine

someone correct me if im wrong pls

bananna_manuk is correct, I misunderstood the original question. The only thing to add is it’s preferable to use structured concurrency (in this case Branch) rather than spawn where possible.