How to Count Player Deaths

I am completely new to this, as in I’ve never written a line of code in my life, but the prospect of it is interesting to me and I feel like I’ve got some fun game ideas, so I went through all of the tutorials and I feel like I’m able to understand the basic fundamentals of it.

I’m trying to write a script that keeps track of the total player deaths per match in the FFA template.

My goal is to adjust attributes of the player based on the amount of times they have been killed.

I’ve tried both creating a property in HealthScript and creating an individual script to track it. The problem I keep running into is how to increase the default value of the number.

The property I’ve defined as a number named “deathCount”

As a property I’ve attempted to increase it by adding

"self.property.deathCount = self.property.deathCount +1

Under the Init() [thinking that the count increased Everytime the HealthScript is initialized] and I’ve attempted to add it under the self:Kill script within the OnDamage() function.

I’m guessing [probably wrong] that it’s not working because the script reinitializing resets the default value of number properties.

Could anyone please tell me what I am doing wrong and provide a solution?

Thank you!

2 Likes

Hey. It’s great to hear you’re jumping in the code side of things :slight_smile:

So it seems like you’re on the right lines but as you said the Init() will be resetting that number each time the player respawns. What you’d want to do here is actually have that count on the User, which is never re-initialised. Think of the user as the human actually playing the game where the player is the character in the game.

What you could do is have a script on the the user which tracks the count (and resets when you want it to i.e. at the end of a match). Then, when the player is killed in the healthScript you can call self:GetEntity():GetUser():SendToScripts("IncreaseCount") to increase the number on the user (assuming you have a function called IncreaseCount to handle that)

Does that make sense? There is a tutorial here which covers the Player/User relationship which may help: https://tutorials.crayta.com/the-relationship-between-player-and-user/

Good luck!

3 Likes

Thank you for the reply! I’ll give it another shot

2 Likes