How to make an accurate K/D leaderboard

Hello,
I’m trying to make an K/D leaderboard on my own, and I’ve watched many videos, however none of them are working. I have some Custom weapons that do have a place for a script that may help with the K/D leaderboard.

Any help is appreciated!,
OceanTubez

ya pretty much gotta just do arithmetic inside the gun for the kills on the leaderboard each time someone is killed.
im sure theres a function in most weapons that handles the killing that you can do that.

also about the deaths, just use humanoid.Died to commit arithmetic

With most guns in roblox, on kill a creator ObjectValue is created inside of the recently passed humanoid. This allowed with the .Died event can be formed to created a working Kills and Death leaderstats system

A script using this method

local Players = game:GetService('Players') 

Players.PlayerAdded:Connect(function(player) -- when the player joins

  local leaderstats = Instance.new('Folder') -- create a folder tohold the stats
  leaderstats.Name = 'leaderstats' -- name it leaderstats to allow the leaderboard to display stats

  local KillsValue = Instance.new('IntValue') -- create a kills stat
  KillsValue.Name = 'Kills'
  KillsValue.Parent = leaderstats

  local DeathsValue = Instance.new('IntValue') -- create a deaths stat
  DeathsValue.Name = 'Deaths'
  DeathsValue.Parent = leaderstats
  
  leaderstats.Parent = player
  
  player.CharacterAdded:Connect(character) -- when the player spawns
    local humanoid = character:WaitForChild('Humanoid')
    
    humanoid.Died:Wait() -- wait until the player dies

    DeathsValue.Value += 1 -- add a death to the player
    
    local creator = humanoid:FindFirstChild('creator') -- see if a weapon killed them and placed a value
    
    if creator and creator.Value then -- check if the killer exists
      local killer = creator.Value

      local KillerKills = killer:WaitForChild('leaderstats'):WaitForChild('Kills') -- get the killer's kills stat
      
      if KillerKills then
        KillerKills.Value += 1 -- reward a kill
      end
    end
  end)
end)

Also here’s the function to put inside of your weapon scripts

local function TagHumanoid(hum, killer)
  local creator = Instance.new('ObjectValue')
  creator.Name = 'creator'
  creator.Value = killer
  return creator
end
1 Like

The deaths counter is working, but the kills is not. I appreciate that you tried to point it out : )

1 Like