# Help with Timer Script

**URL:** <https://forums.unrealengine.com/t/help-with-timer-script/1912079>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [June 22, 2024, 12:11am UTC](https://forums.unrealengine.com/t/help-with-timer-script/1912079 "2024-06-22T00:11:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mock04](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mock04](https://forums.unrealengine.com/u/Mock04)\
**Post date:** [June 22, 2024, 12:11am UTC](https://forums.unrealengine.com/t/help-with-timer-script/1912079/1 "2024-06-22T00:11:13Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![laggyluk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@laggyluk](https://forums.unrealengine.com/u/laggyluk)\
**Post date:** [June 22, 2024, 6:58am UTC](https://forums.unrealengine.com/t/help-with-timer-script/1912079/2 "2024-06-22T06:58:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mock04](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mock04](https://forums.unrealengine.com/u/Mock04)\
**Post date:** [June 23, 2024, 2:34am UTC](https://forums.unrealengine.com/t/help-with-timer-script/1912079/3 "2024-06-23T02:34:16Z")

</div>

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/f/e/afe0f81040d7033ac022fdce4fb8ec6496cdc7af.png)  
 ![Screenshot 2024-06-22 212542](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/8/d/b8d73a1bdc9c6c38a9fc91d52fff7c220c4874bf.png)  
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

---

<div class="post-metadata">

**Author:** ![laggyluk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@laggyluk](https://forums.unrealengine.com/u/laggyluk)\
**Post date:** [June 23, 2024, 7:25am UTC](https://forums.unrealengine.com/t/help-with-timer-script/1912079/4 "2024-06-23T07:25:59Z")

</div>

> **[Struct | Unreal Editor para Fortnite Documentación | Epic Developer Community](https://dev.epicgames.com/documentation/es-es/uefn/struct-in-verse)**
>
> Struct sirve para agrupar distintas variables relacionadas.

> **[Map | Unreal Editor for Fortnite Documentation | Epic Developer Community](https://dev.epicgames.com/documentation/en-us/uefn/map-in-verse)**
>
> A map is a container where you can store values associated with other values, called key-value pairs, and access the elements by their unique keys.

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
