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 = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player -- Create kills IntValue local kills = Instance.new("IntValue") kills.Name = "Kills" kills.Parent = leaderstats kills.Value = 0 -- Create deaths IntValue local deaths = Instance.new("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 = Instance.new("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 end -- Whenever the player's Kills or Deaths updates, the "updateRatio" function is activated kills.Changed:Connect(updateRatio) deaths.Changed:Connect(updateRatio) end Players.PlayerAdded:Connect(createLeaderstats)
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.