How would you script a K/D ratio?

Is there any way to script a K/D ratio using kills and deaths?


Hello, I know a free model that dose this here:

(I did not make this)

I’m not sure where you’re looking to implement this, but finding that ratio can be done by dividing the Kills by the Deaths, as it implies (since I presume you’re not just wondering how to add in kills and deaths as a statistic):

Basic example with leaderstats:

local Players = game:GetService("Players")

local function createLeaderstats(player)

-- Create leaderstats folder
    local leaderstats ="Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

-- Create kills IntValue
    local kills ="IntValue")
    kills.Name = "Kills"
    kills.Parent = leaderstats
    kills.Value = 0

-- Create deaths IntValue
    local deaths ="IntValue")
    deaths.Name = "Deaths"
    deaths.Parent = leaderstats
    deaths.Value = 0

-- Create KDR NumberValue (not IntValue since this is not guaranteed to be an integer)
    local ratio ="NumberValue")
    ratio.Name = "KDR"
    ratio.Parent = leaderstats
    ratio.Value = 0

    local function updateRatio()
        local newRatio = kills.Value / deaths.Value
        ratio.Value = newRatio -- Updates KDR NumberValue to the new ratio

-- Whenever the player's Kills or Deaths updates, the "updateRatio" function is activated


I think the simplest way to script a K/D ratio is base it on a mathmatical formula that will help you figure it out.

Thanks! This example helped me.

1 Like

How do you round it off smoothly like in phantom forces

Idk how exactly PF does their K/D numbers, but you’d you’d want to do something along these lines:

local num = 5.28463 --// This would be the K/D number
local new = math.floor(num * 10) / 10
print(new) --// 5.2
1 Like