# Gun game issue skipping guns sometimes

**URL:** <https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite\
**Created:** [October 27, 2023, 11:11am UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790 "2023-10-27T11:11:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![TFA\_aaronfhd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TFA\_aaronfhd](https://forums.unrealengine.com/u/TFA_aaronfhd)\
**Post date:** [October 27, 2023, 11:11am UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/1 "2023-10-27T11:11:54Z")

</div>

Having Issue with my gun game. Sometimes it will skip gun for no reason. But most of the time is ok.

I don’t if its a issue when players join or what.

Thanks

Here is the map 7298-1477-0485

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [October 27, 2023, 11:56am UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/2 "2023-10-27T11:56:01Z")

</div>

Can you show your script ?

---

<div class="post-metadata">

**Author:** ![TFA\_aaronfhd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TFA\_aaronfhd](https://forums.unrealengine.com/u/TFA_aaronfhd)\
**Post date:** [October 27, 2023, 12:34pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/3 "2023-10-27T12:34:10Z")

</div>

I thought I pasted it oops will paste it again, still learning verse.

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 }

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{}

@editable
var Sentries : []sentry_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{}

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)

    # Get all the players in the experience
    AllPlayers := GetPlayspace().GetPlayers()
    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) 

 # Subscribe to new players joining the game
 for (Sentry : Sentries):
    Sentry.EliminatedEvent.Subscribe(TestPlayerEliminated) # Subscribe to each Sentry

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

 

# Event that handles when a player is eliminated
OnPlayerEliminated(Result:elimination_result):void=
    Print("Player Eliminated")
    EliminatingCharacter := Result.EliminatingCharacter
    if (FortCharacter := EliminatingCharacter?):
        if (EliminatingAgent := FortCharacter.GetAgent[]):
            GrantNextWeapon(EliminatingAgent)

TestPlayerEliminated(Agent: ?agent) : void =
    Print("Sentry Down!")
    if(EliminatingAgent := Agent?):
        GrantNextWeapon(EliminatingAgent)

# Check if there is a winner for the game, if not then grant the next weapon
GrantNextWeapon(Agent:agent):void=
    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]):
                ItemGranter.GrantItem(Agent)
            
            if (set AgentMap[Agent] = CurrentItemNumber) {}

# 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

EndGame(Agent:agent):void=
    EndGameDevice.Activate(Agent)

# Handles a new player joining the game

OnPlayerAdded(InPlayer : player) : void =
    Print("A New Player Joined!")
    if:
        FortCharacter := InPlayer.GetFortCharacter[]
        set AgentMap[InPlayer] = 1
        FirstItemGranter:= WeaponItemGranters[0]
    then:
        FirstItemGranter.GrantItem(InPlayer) 
        Print("Set new player weapon tier to 0 in the TeamMap")
        FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) # subscribe to this player's elimination event

```

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [October 27, 2023, 1:19pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/4 "2023-10-27T13:19:36Z")

</div>

Looks okay to me, but is this happening when players join twice ? I believe the `InPlayer.FortCharacter[].EliminatedEvent().Subscribe` will stay subscribed if you don’t unsubscribe inside `OnPlayerRemoved`

Otherwise I’m not sure, maybe check if you don’t have any additional direct event binding on your granters?

---

<div class="post-metadata">

**Author:** ![TFA\_aaronfhd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TFA\_aaronfhd](https://forums.unrealengine.com/u/TFA_aaronfhd)\
**Post date:** [October 27, 2023, 1:37pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/5 "2023-10-27T13:37:47Z")

</div>

Dont’ think so How would I do a player removed.

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [October 27, 2023, 1:42pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/6 "2023-10-27T13:42:20Z")

</div>

The same way you did OnPlayerAdded 👍

---

<div class="post-metadata">

**Author:** ![TFA\_aaronfhd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TFA\_aaronfhd](https://forums.unrealengine.com/u/TFA_aaronfhd)\
**Post date:** [October 27, 2023, 2:13pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/7 "2023-10-27T14:13:14Z")

</div>

Thanks will give it a try

---

<div class="post-metadata">

**Author:** ![TFA\_aaronfhd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TFA\_aaronfhd](https://forums.unrealengine.com/u/TFA_aaronfhd)\
**Post date:** [October 28, 2023, 11:53am UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/8 "2023-10-28T11:53:50Z")

</div>

Hmm can’t figure out how to unsubscribe, and there really is not much documentation on how to do that.

Do you have a example? OnplayerRemove Unsubscribe?

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [October 28, 2023, 11:56am UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/9 "2023-10-28T11:56:45Z")

</div>

So basically, every `subscribable.Subscribe()` function returns a `cancelable` type which can be canceled by calling `cancelable.Cancel()` (see [cancelable interface](https://dev.epicgames.com/documentation/en-us/uefn/verse-api/versedotorg/verse/cancelable))

Requires a bit of programing knowledge for sure

---

<div class="post-metadata">

**Author:** ![TFA\_aaronfhd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TFA\_aaronfhd](https://forums.unrealengine.com/u/TFA_aaronfhd)\
**Post date:** [October 28, 2023, 12:04pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/10 "2023-10-28T12:04:05Z")

</div>

> [@TFA\_aaronfhd](#):
>
> ```auto
> @editable
> EndGameDevice : end_game_device = end_game_device{}
> 
> # Array of item granters used to grant the weapons
> @editable
> var WeaponItemGranters : []item_granter_device = array{}
> 
> @editable
> var Sentries : []sentry_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{}
> 
> 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)
> 
> # Get all the players in the experience
> AllPlayers := GetPlayspace().GetPlayers()
> 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) 
> 
> # Subscribe to new players joining the game
> for (Sentry : Sentries):
> Sentry.EliminatedEvent.Subscribe(TestPlayerEliminated) # Subscribe to each Sentry
> 
> GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)
> 
>  
> 
> # Event that handles when a player is eliminated
> OnPlayerEliminated(Result:elimination_result):void=
> Print("Player Eliminated")
> EliminatingCharacter := Result.EliminatingCharacter
> if (FortCharacter := EliminatingCharacter?):
> if (EliminatingAgent := FortCharacter.GetAgent[]):
> GrantNextWeapon(EliminatingAgent)
> 
> TestPlayerEliminated(Agent: ?agent) : void =
> Print("Sentry Down!")
> if(EliminatingAgent := Agent?):
> GrantNextWeapon(EliminatingAgent)
> 
> # Check if there is a winner for the game, if not then grant the next weapon
> GrantNextWeapon(Agent:agent):void=
> 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]):
> ItemGranter.GrantItem(Agent)
>             
> if (set AgentMap[Agent] = CurrentItemNumber) {}
> 
> # 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
> 
> EndGame(Agent:agent):void=
> EndGameDevice.Activate(Agent)
> 
> # Handles a new player joining the game
> 
> OnPlayerAdded(InPlayer : player) : void =
> Print("A New Player Joined!")
> if:
> FortCharacter := InPlayer.GetFortCharacter[]
> set AgentMap[InPlayer] = 1
> FirstItemGranter:= WeaponItemGranters[0]
> then:
> FirstItemGranter.GrantItem(InPlayer) 
> Print("Set new player weapon tier to 0 in the TeamMap")
> FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) # subscribe to this player's elimination event
> 
> ```

Thanks but still a noob at this verse script and I learn very well by example so if you can help write a section that would really apprciated

---

<div class="post-metadata">

**Author:** ![TFA\_aaronfhd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TFA\_aaronfhd](https://forums.unrealengine.com/u/TFA_aaronfhd)\
**Post date:** [October 28, 2023, 6:08pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/11 "2023-10-28T18:08:21Z")

</div>

Ok I think I got it

I added these 2

GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)

OnPlayerRemoved(InPlayer : player) : void =  
Print(“A New Player Joined!”)  
if:  
FortCharacter := InPlayer.GetFortCharacter  
#set AgentMap[InPlayer] = 1  
#FirstItemGranter:= WeaponItemGranters[0]  
then:  
#FirstItemGranter.GrantItem(InPlayer)  
#Print(“Set new player weapon tier to 0 in the TeamMap”)  
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated).Cancel # Unsubscribe to this player’s elimination event

---

<div class="post-metadata">

**Author:** ![TFA\_aaronfhd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TFA\_aaronfhd](https://forums.unrealengine.com/u/TFA_aaronfhd)\
**Post date:** [October 30, 2023, 6:32pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/12 "2023-10-30T18:32:32Z")

</div>

Seems to still not work as if I am player 0 and player 1 leaves the game, player 0 skips guns

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [October 30, 2023, 7:34pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/13 "2023-10-30T19:34:10Z")

</div>

Can you show your updated formatted code ?

---

<div class="post-metadata">

**Author:** ![TFA\_aaronfhd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TFA\_aaronfhd](https://forums.unrealengine.com/u/TFA_aaronfhd)\
**Post date:** [October 30, 2023, 7:50pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/14 "2023-10-30T19:50:14Z")

</div>

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 }

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{}

@editable
var Sentries : []sentry_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{}

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)

    # Get all the players in the experience
    AllPlayers := GetPlayspace().GetPlayers()
    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) 

 # Subscribe to new players joining the game
 for (Sentry : Sentries):
    Sentry.EliminatedEvent.Subscribe(TestPlayerEliminated) # Subscribe to each Sentry

 GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)
 GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)
 

# Event that handles when a player is eliminated
OnPlayerEliminated(Result:elimination_result):void=
    Print("Player Eliminated")
    EliminatingCharacter := Result.EliminatingCharacter
    if (FortCharacter := EliminatingCharacter?):
        if (EliminatingAgent := FortCharacter.GetAgent[]):
            GrantNextWeapon(EliminatingAgent)

TestPlayerEliminated(Agent: ?agent) : void =
    Print("Sentry Down!")
    if(EliminatingAgent := Agent?):
        GrantNextWeapon(EliminatingAgent)

# Check if there is a winner for the game, if not then grant the next weapon
GrantNextWeapon(Agent:agent):void=
    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]):
                ItemGranter.GrantItem(Agent)
            
            if (set AgentMap[Agent] = CurrentItemNumber) {}

# 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

EndGame(Agent:agent):void=
    EndGameDevice.Activate(Agent)

# Handles a new player joining the game

OnPlayerAdded(InPlayer : player) : void =
    Print("A New Player Joined!")
    if:
        FortCharacter := InPlayer.GetFortCharacter[]
        set AgentMap[InPlayer] = 1
        FirstItemGranter:= WeaponItemGranters[0]
    then:
        FirstItemGranter.GrantItem(InPlayer) 
        Print("Set new player weapon tier to 0 in the TeamMap")
        FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) # subscribe to this player's elimination event

OnPlayerRemoved(InPlayer : player) : void =
    Print("A New Player Joined!")
    if:
        FortCharacter := InPlayer.GetFortCharacter[]
    then:
        FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated).Cancel # Unsubscribe to this player's elimination event

```

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [October 30, 2023, 7:56pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/15 "2023-10-30T19:56:14Z")

</div>

Can you post the formatted code ?

---

<div class="post-metadata">

**Author:** ![TFA\_aaronfhd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TFA\_aaronfhd](https://forums.unrealengine.com/u/TFA_aaronfhd)\
**Post date:** [October 30, 2023, 7:58pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/16 "2023-10-30T19:58:35Z")

</div>

```auto

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 }

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{}

    @editable
    var Sentries : []sentry_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{}

    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)

        # Get all the players in the experience
        AllPlayers := GetPlayspace().GetPlayers()
        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) 
    
     # Subscribe to new players joining the game
     for (Sentry : Sentries):
        Sentry.EliminatedEvent.Subscribe(TestPlayerEliminated) # Subscribe to each Sentry

     GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)
     GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)
     

    # Event that handles when a player is eliminated
    OnPlayerEliminated(Result:elimination_result):void=
        Print("Player Eliminated")
        EliminatingCharacter := Result.EliminatingCharacter
        if (FortCharacter := EliminatingCharacter?):
            if (EliminatingAgent := FortCharacter.GetAgent[]):
                GrantNextWeapon(EliminatingAgent)
    
    TestPlayerEliminated(Agent: ?agent) : void =
        Print("Sentry Down!")
        if(EliminatingAgent := Agent?):
            GrantNextWeapon(EliminatingAgent)

    
    # Check if there is a winner for the game, if not then grant the next weapon
    GrantNextWeapon(Agent:agent):void=
        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]):
                    ItemGranter.GrantItem(Agent)
                
                if (set AgentMap[Agent] = CurrentItemNumber) {}

    # 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

    EndGame(Agent:agent):void=
        EndGameDevice.Activate(Agent)

    # Handles a new player joining the game

    OnPlayerAdded(InPlayer : player) : void =
        Print("A New Player Joined!")
        if:
            FortCharacter := InPlayer.GetFortCharacter[]
            set AgentMap[InPlayer] = 1
            FirstItemGranter:= WeaponItemGranters[0]
        then:
            FirstItemGranter.GrantItem(InPlayer) 
            Print("Set new player weapon tier to 0 in the TeamMap")
            FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) # subscribe to this player's elimination event
    
    OnPlayerRemoved(InPlayer : player) : void =
        Print("A New Player Joined!")
        if:
            FortCharacter := InPlayer.GetFortCharacter[]
        then:
            FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated).Cancel # Unsubscribe to this player's elimination event

```

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [October 30, 2023, 8:14pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/17 "2023-10-30T20:14:16Z")

</div>

Thanks, so here you’re only getting the reference to the `Cancel` function, you’re not actually calling it, maybe doing `.Cancel()` would work better.

But even with this, you’re only cancelling a new subscriber you just created (using `.Subscribe()` )

The `.Subscribe()` call you make in OnBegin returns an actual `cancelable`, and it’s this one you need to call `.Cancel()` on.

But it’s still strange imo that your player gets granted a weapon when the other player leaves, this is not what I understood in the first place…

---

<div class="post-metadata">

**Author:** ![TFA\_aaronfhd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TFA\_aaronfhd](https://forums.unrealengine.com/u/TFA_aaronfhd)\
**Post date:** [October 30, 2023, 9:43pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/18 "2023-10-30T21:43:08Z")

</div>

> [@TFA\_aaronfhd](#):
>
> `FortCharacter.EliminatedEvent().Subscribe`

Sorry Let me try and explain a bit better.

Player 0 is on Weapon 1  
Player 1 gets a elimiation which moves him to Weapon 2.  
Player 1 leaves the Game  
Player 0 gets an elimination which moves him to weapon 3(should be weapon 2)

So it is skipping for the player 0 if that makes sense.

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [October 30, 2023, 10:54pm UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/19 "2023-10-30T22:54:03Z")

</div>

Does the issue happen if player doesn’t reconnect ? You didn’t try my solution yet, maybe it will fix it.

---

<div class="post-metadata">

**Author:** ![TFA\_aaronfhd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TFA\_aaronfhd](https://forums.unrealengine.com/u/TFA_aaronfhd)\
**Post date:** [October 31, 2023, 1:38am UTC](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790/20 "2023-10-31T01:38:28Z")

</div>

I thought that onplayerRemoved function does this.

I call `GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)`

So this gets the playspace and the player removed then I call the function which

```auto
OnPlayerRemoved(InPlayer : player) : void =
        Print("Player has left")
        if:
            FortCharacter := InPlayer.GetFortCharacter[]
        then:
            FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated).Cancel # Unsubscribe to this 

```

So this function from what I can tell gets the player and then cancels it.

Or is this not where I am supposed to do this.

thanks for the help by the way, Verse is not my cup of tea compared to other languages

[Next page](https://forums.unrealengine.com/t/gun-game-issue-skipping-guns-sometimes/1347790.md?page=2)
