How Can I Make NPC Kills Count

Hi I’m The_BorwnDoggy, this is my first post on this forum. I needed some help with making my kills count on my leaderstats. The reason its not working is because I’m making an FPS game, (my first game), and the way the NPCs are kill is with a gun, which is a tool.

Here the code I have for the leaderstats which as a said doesn’t work.

    local function addBoard(player)
	local board ="Folder", player)
	board.Name = "leaderstats"
	local kills ="IntValue", board)
	kills.Name = "Kills"
	local deaths ="IntValue", board)
	deaths.Name = "Deaths"

local function onCharacterRemoving(char)
	local player = game.Players:GetPlayerFromCharacter(char)
	local deaths = player.leaderstats.Deaths
	deaths.Value = deaths.Value + 1

local function onPlayerAdded(player)


I would be extremely happy if anyone could help me with this :slight_smile:

1 Like

Track the NPC’s death using Humanoid.Died event.

Also, Kills are different from Deaths. Remember that necessarily someone that dies isn’t killed, I recommend you look for who killed who when someone uses a weapon, aka your gun tool(s).

1 Like

Thanks for the quick response,

Would I need to make a new local script inside the tool to track the NPC’s death, or just add it to my leaderstats one

To accurately track deaths/kills, it should not be updated from a local script nor should any killing be recorded through the local script. This is open to exploitation.

Local scripts can detect the action of the player pressing their mouse and thus allowing you to have them shoot their gun but the bullet hitting whom should be checked or done on the server before allowing any damage and then you can track for kills that way.