The Scoreboard Snitch: Reading Player Stats in Verse
The Scoreboard Snitch: Reading Player Stats in Verse
So you’ve built a cool island, but right now it’s basically a ghost town. You drop in, run around, and nothing happens because your code doesn’t know who is playing or how well they’re doing. That’s where GetCurrentScore comes in. Think of it as the ultimate scoreboard snitch. It’s a function that looks at a specific player (the "Agent") and tells you their current point total, just like the stats screen at the end of a match. Without this, your game is flying blind. Let’s fix that.
What You'll Learn
- What an "Agent" is (spoiler: it’s just the player).
- How to ask the game for a player’s current score using
GetCurrentScore. - How to use that score to trigger fun, chaotic events based on how well (or poorly) a player is doing.
How It Works
In Fortnite, you know that when you get an elimination, your score goes up. In Verse, we need a way to read that number to do something cool, like spawn a boss if someone hits 50 points, or give them a heal if they’re below 10.
Here is the breakdown of the concept:
- The Agent: In Verse, every player in the game is referred to as an
Agent. Think of this as the "Player Character" slot. If you want to know how you are doing, you pass yourself (the local player) as the Agent. - The Function (
GetCurrentScore): This is a question you ask the game engine. It’s like pressing the "Stats" button on your controller. It takes one input: the Agent. It gives back one output: anint(integer, which just means a whole number like 0, 1, 50, or 999). - The Result: The function returns the current score for that specific Agent. If the score is 0, it returns 0. If they’ve racked up some eliminations or completed objectives, it returns that number.
Why does this matter?
Imagine a "Revenge Trap." You want a trap to only activate if the player has already killed 5 people. You can’t just guess; you have to ask the game, "Hey, what’s this player’s score right now?" GetCurrentScore is the answer.
Let's Build It
We are going to build a "Score Check Trigger." When a player steps on a pressure plate, the game will check their score.
- If their score is greater than 0, a message pops up saying "You're a killer!" and a green light turns on.
- If their score is 0, it says "Newbie alert!" and a red light turns on.
This teaches you how to read data and make decisions based on it.
The Verse Code
Copy this into a Verse file in UEFN. Make sure you have a Score Manager device and a Switch device (or a Prop Mover/Light if you prefer visuals) placed in your level.
using { /Fortnite.com/Devices }
# We define a simple script that checks the player's score when they step on a plate.
# 'Score_Checker' is the name of our script object.
Score_Checker: script =
# This is a 'Signal'. Think of it as a wire connecting two devices.
# When the 'Pressure_Plate' is stepped on, this signal fires.
On_Player_Steps: signal() = Pressure_Plate.Stepped
# This is the 'Event' that runs when the signal fires.
OnBegin<override>()<suspends>:
# 1. Get the Local Player (The Agent)
# In Verse, 'Get_Local_Player()' gives us the Agent of the person playing.
# If you want to check a *specific* player, you'd pass their Agent ID here.
local_player: agent = Get_Local_Player()
# 2. Ask the Score Manager for the current score
# We use the 'Score_Manager' device we placed in the level.
# GetCurrentScore(local_player) asks: "What is this player's score?"
# It returns an 'int' (a whole number).
current_points: int = Score_Manager.GetCurrentScore(local_player)
# 3. Check the score and react
# We use an 'if' statement. This is like a decision gate.
if current_points > 0:
# If score is > 0, turn on the 'Good_Light' switch
Good_Light.SwitchOn()
# Print a message to the player (like a chat message)
Print_To_Player(local_player, "You're a killer! Score: " + As_String(current_points))
else:
# If score is 0 (or negative, though unlikely), turn on 'Bad_Light'
Bad_Light.SwitchOn()
Print_To_Player(local_player, "Newbie alert! Score: " + As_String(current_points))
# This is just to keep the script running so it can listen for events.
OnEnd<override>()<suspends>:
pass
Walkthrough of the Code
using { /Fortnite.com/Devices }: This line tells Verse, "Hey, I want to use the built-in Fortnite devices like Score Managers and Switches." Without this, Verse doesn’t know whatScore_Manageris.Score_Checker: script =: This creates our main script container. Everything inside it belongs to this script.On_Player_Steps: signal() = Pressure_Plate.Stepped: We are connecting a "wire" from a device calledPressure_Plateto our script. When the plate is stepped on, theSteppedevent fires, which triggers our script.local_player: agent = Get_Local_Player(): This is crucial. We need to know who to check.Get_Local_Player()grabs the Agent of the person currently playing.current_points: int = Score_Manager.GetCurrentScore(local_player): This is the core lesson. We are calling theGetCurrentScorefunction. We passlocal_playerinto the parentheses. The function looks up that player’s score and hands it back to us, storing it in the variablecurrent_points.if current_points > 0:: This is a basic condition. If the number we got back is bigger than zero, do the first thing.Good_Light.SwitchOn(): We assume you have a Switch device namedGood_Lightin your level. This turns it on.Print_To_Player(...): This sends a text message to the player’s screen. Note that we useAs_String()because you can’t add text and numbers together directly in Verse. It converts the number (int) into text (string).
Try It Yourself
Challenge: The "Heal Goblin"
Modify the code above to create a "Heal Goblin" system.
- Place a
Item Granterdevice in your level and name itHeal_Granter. - Change the
ifcondition to check if the player’s score is less than 5. - If their score is less than 5, activate
Heal_Granterto give them a shield potion. - If their score is 5 or more, do nothing (or print "No more freebies!").
Hint: You’ll need to change current_points > 0 to current_points < 5 and call Heal_Granter.Grant() (or however your Item Granter is set up to fire). Check the UEFN documentation for Item_Granter to see the exact function name to grant an item!
Recap
GetCurrentScoreis a function that asks the game for a specific player’s current score.- It requires an
Agent(the player) as input and returns anint(number). - You can use this number in
ifstatements to create dynamic gameplay that reacts to how well a player is doing. - Always remember to use
As_String()when you want to display numbers in text messages!
References
- https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/devices/score_manager_device/getcurrentscore
- https://dev.epicgames.com/documentation/en-us/fortnite/verse-api/fortnitedotcom/devices/score_manager_device/getcurrentscore
- https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/devices/conditional_button_device/getitemscore
- https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/devices/switch_device/getcurrentstate-1
- https://dev.epicgames.com/documentation/en-us/fortnite/verse-api/fortnitedotcom/devices/switch_device/getcurrentstate-1
Verse source files
- 01-fragment.verse · fragment
Turn this into a guided course
Add getcurrentscore to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.
References
Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.