Function doesn't run when elimination occurs

I have been working on a small test code to make it so that when a player dies, they join the team of the player who kills them.

The issue is that the function to swap the team isn’t running when a player dies.
(The code was tested using the test players from the Fortnite creative debug menu.)

My current code is:

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



#hello
#hope this code is readable (:
#Made By RealMegaSteveYT//Megastevian


infectionMode := class(creative_device):
    
    OnBegin<override>()<suspends>:void=
        Print("test")
        AllPlayers := GetPlayspace().GetPlayers()
        for(Player:AllPlayers, FortCharacter:= Player.GetFortCharacter[]):
            FortCharacter.EliminatedEvent().Subscribe(ElimManage) #problem is probably here
    
#a lot of parts are from the unreal engine forums because im just now starting with verse
ElimManage(Result:elimination_result):void=
    Print("ElimManageStart") #this print does not run
    TeamCollection := creative_device{}.GetPlayspace().GetTeamCollection()
    eliminatedPlayer := Result.EliminatedCharacter

    if:
        killedAgent := eliminatedPlayer.GetAgent[]

        killerChar := Result.EliminatingCharacter?
        KillerAgent := killerChar.GetAgent[]
        killerTeam := TeamCollection.GetTeam[KillerAgent]
        Teams := TeamCollection.GetTeams()
        killerTeamGet := TeamCollection.GetTeams().Find[killerTeam]

    then:
        Print("Death detected: commencing player check")
        if(KillerAgent <> killedAgent):
            Print("Death has been confirmed to be by other player")
            AssignToTeamByIndex(killedAgent, killerTeamGet)
                    
#megastevian
AssignToTeamByIndex(Agent: agent, Index:int):void=
            TeamCollection := creative_device{}.GetPlayspace().GetTeamCollection()
	        Teams := TeamCollection.GetTeams()
	        if (
	            Team := Teams[Index]
	            TeamCollection.AddToTeam[Agent, Team]
	        )
	            then:
	                Print("Team assigned {Index}")
	            else:
	                Print("Could not assign team") 

Sorry if the code is bad. I used a lot of info I got from the forums since I’m new to Verse and recently decided to try it out for this project after first using both Python and GDScript.

Does the '“test” print get output?

Not sure what the issue is, maybe breaking the lines out like this could help.

Print(“test”)
for (Player : AllPlayers):
    Print("test player")
    FortCharacter := Player.GetFortCharacter[]
    FortCharacter.EliminatedEvent().Subscribe(ElimManage)

The “test player” print will let you know if it’s seeing any players.


i just checked the issue is is that it doesn’t work when players join mid game

Sadly, I am not smart enough to fix this, as I have tried to, but it sadly didn’t work.

Hello @realmegasteveYT1 how are you??

I’ve been testing and your original code works perfectly!

The problem is that the “test players” are not counted as real players for some reason! I’ve tested your code with a friend and it works!

You don’t need to change anything! Here is a video proving it:

Let me know if you need more help!

1 Like

thanks so much BRG for the awnser genuinly thanks so much i would have been stuck on this for like forever