How to fix this "freeze closest player" code?

I found online a code for a “freeze closest player” power, but there was no activator for the function to freeze the closest player. So I tried to include the trigger for freezing the player to be performed when that player checks a switch and the result is on, but it seems that I don’t know how to do that lol

The code:

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


FreezeClosestPlayer := class(creative_device):
    var Targets : []fort_character = array{}
    var NewTargets : []fort_character = array{}
    @editable FreezeClosestProp : creative_prop = creative_prop{}
    @editable FreezeTime : float = 0.0
    @editable FreezeClosestSound : audio_player_device = audio_player_device{}
    @editable FreezeClosestMSG : hud_message_device = hud_message_device{}
    @editable SwitchChecker : switch_device = switch_device{}
    


    @editable Cooldown : float = 0.0
    var MaybeCooldown : logic = false
    @editable FreezeClosestTimer : timer_device = timer_device{}
    @editable CooldownMSG : hud_message_device = hud_message_device{}


    OnBegin<override>()<suspends>:void=
        SwitchChecker.IfOnWhenCheckedEvent.Subscribe(FreezePlayer)
        FreezeClosestTimer.SetMaxDuration(Cooldown)
        set MaybeCooldown = false
        FreezeClosestTimer.SuccessEvent.Subscribe(ResetCooldown)
        FreezeClosestMSG.SetDisplayTime(FreezeTime)
    ResetCooldown(Agent:?agent) : void=
        set MaybeCooldown = false
    

    FreezePlayer(Agent:agent)<suspends> : void=
        if(MaybeCooldown = false):
            FreezeClosestTimer.Start(Agent)
            set MaybeCooldown=true

            set Targets = array{}
            for(Player : GetPlayspace().GetPlayers(),FC := Player.GetFortCharacter[]):
                set Targets += array{FC}
            if(ActivatorPlayer := player[Agent],ActivatorChar := ActivatorPlayer.GetFortCharacter[]):
                if(ActivatorIDX := Targets.Find[ActivatorChar]):
                    if(NEWTARGET := Targets.RemoveElement[ActivatorIDX]):
                        set NewTargets = NEWTARGET
                        if(Target := ActivatorChar.FindNearestTarget[], NewTargets.Length > 0):
                            if(TargetAgent := Target.GetAgent[]):
                                FreezeClosestSound.Play(TargetAgent)
                                FreezeClosestMSG.Show(TargetAgent)
                                if(FreezeClosestProp.TeleportTo[Target.GetTransform().Translation - vector3{Z:=80.0}, Target.GetTransform().Rotation]){} #Required because uefn is weird and broken
                                Target.PutInStasis(stasis_args{})
                                Sleep(FreezeTime)
                                Target.ReleaseFromStasis()
                                if(FreezeClosestProp.TeleportTo[vector3{X:=1000.0,Y:=1000.0,Z:=1000.0},FreezeClosestProp.GetTransform().Rotation]){}
        else:
            CooldownMSG.Show(Agent)


    (FortCharacter : fort_character).FindNearestTarget()<transacts><decides> : fort_character =
        var MaybeTarget : ?fort_character = false
        var NearestLocation : float = 1000000.0
        for (Target : NewTargets):
            if (DistancePlayerToTarget := Distance(Target.GetTransform().Translation, FortCharacter.GetTransform().Translation) < NearestLocation):
                set MaybeTarget = option{Target}
                set NearestLocation = DistancePlayerToTarget
        return MaybeTarget?

What I did was create the editable @editable SwitchChecker: switch_device = switch_device{}

and try to add the line in on_begin:

SwitchChecker.IfOnWhenCheckedEvent.Subscribe(FreezePlayer)
But it gives this error:

[{
“resource”: “/C:/Users/andre/OneDrive/Documentos/Fortnite Projects/Shogunate/Plugins/Shogunate/Content/FreezeClosestPlayer.verse”,
“owner”: “generated_diagnostic_collection_name#0”,
“code”: “3509”,
“severity”: 8,
“message”: “This function parameter expects a value of type tuple()->void, but this argument is an incompatible value of type type{_(:agent):void}.”,
“startLineNumber”: 28,
“startColumn”: 52,
“endLineNumber”: 28,
“endColumn”: 64
}]

Can someone please help me to understand and fix the code?

The issue is the event you subscribed IfOnWhenCheckedEvent doesn’t take in a player agent. I think there is a function CheckState that accepts an agent that you can query to see if the player has that switch off or on but you have to setup the switch to use individual player states in the device settings. I’m not sure I follow 100% what you are trying to do but if I understand you can do Signal Remote Event from signal remote manager → Your freeze player function → check the switch is on for the player → then find the closest player and handle freezing them. The signal remote manager has primary and secondary events you can subscribe to that will return the player agent which you can subscribe to that freeze function.