Help with Timer Script

I am just getting into coding and created this timer script for an obby I made. It works perfectly-- if you only have one person. If you have more than one person it affects everybody. How should I fix this. Looking at videos and stuff i couldn’t find too much but think i need to assign a class with the integers in it. Could you show me what I need to do or at least point me in the right direction thanks!

Here’s the code:
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

Timer_Manager := class(creative_device):

@editable beginning : mutator_zone_device = mutator_zone_device{}
@editable end : mutator_zone_device = mutator_zone_device{}
@editable Screen : hud_message_device = hud_message_device{}
@editable MyPopup : popup_dialog_device = popup_dialog_device{}
@editable EndTele : teleporter_device = teleporter_device{}

var TimeStart : logic = false

var Seconds : int = 00
var Minutes : int = 0

S2M <localizes> (String : string) : message = "{String}"

OnBegin<override>()<suspends>:void=
    beginning.AgentEntersEvent.Subscribe(OnStart)
    end.AgentEntersEvent.Subscribe(OnFinish)
    Screen.SetText(S2M("{Minutes}:0{Seconds}"))
    MyPopup.RespondingButtonEvent.Subscribe(OnReset)
    EndTele.TeleportedEvent.Subscribe(OnReset1)

OnStart(Agent : agent) : void=
    if(TimeStart = true):

    else:
        set TimeStart = true
        spawn {BeginTimer()}

OnReset(Agent : agent, Number : int) : void=
    if(Number = 0):
        set TimeStart = false
        set Minutes = 0
        set Seconds = 0
        Screen.SetText(S2M("{Minutes}:0{Seconds}"))
    else:

OnReset1(Agent : agent) : void=
    set TimeStart = false
    set Minutes = 0 
    set Seconds = 0
    Screen.SetText(S2M("{Minutes}:0{Seconds}"))
    

OnFinish(Agent : agent) : void=
    set TimeStart = false


BeginTimer() <suspends> : void=
    Sleep(1.0)
    if(TimeStart = true):
        loop:
            set Seconds += 1
            if(Seconds = 60):
                set Seconds =0
                set Minutes += 1
            if(Seconds < 10):
                Screen.SetText(S2M("{Minutes}:0{Seconds}"))
            else:
                Screen.SetText(S2M("{Minutes}:{Seconds}"))
            Sleep(1.0)
            if(TimeStart = false):
                break

You didn’t stated what exactly is desired behavior here but it looks like you have one set of variables for timer handling but code will run for each player which effectively sets correct bahavior only for the last one?
If you wanna have multiple ‘timers’, one for each player you either need to have one ‘timer device’ per player or have one device and store variables in array (or map) of structs, where struct holds timer variables and array index maps to player index.

Thanks for the reply! I have this script run with a hud message device to constantly display the timer from when someone starts the obby until they complete it .
Screenshot 2024-06-22 212527
Screenshot 2024-06-22 212542
What I was trying to do is have the timer start and stop for each individual person. My problem is that whenever one person starts the obby their time is displayed for all players.

So what you are saying is that either I would have to have an individual device for each player or modify the code to make map for each player.

To do the second option would i have to

  1. Make a map in the code with the variables
  2. assign the map to each player
  3. then have the code edit the variables for each player

how would I put the different integers inside of the map?
and how would i give it to each person?
Thank you so much for the help

I’m a verse semi-noob myself so writing the code would take me some time, if you don’t know how maps or structs work then it would be definitely easier for you to setup one timer device per spawned player