Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is this Kill/Death Ratio script not working right?

This script is supposed to tell you your KDR (meaning the value has to be a NumberValue). However, I want to the script to identify when the KDR is "NAN" or "INF" and say something different for the values in that case (0 and the amount of kills you have respectively)

Output is giving me nothing. I have no idea why the script isn't working.

Can someone please help me?

Here's the script:

local Player = game.Players.LocalPlayer
local Stats = Player.leaderstats
local Div = (Stats.Kills.Value/Stats.Deaths.Value)
local Number = 0

while wait (0.1) do
	if Div == "INF" and Stats.Kills.Value > 0 then
		Number.Value = Stats.Kills.Value
	elseif Number == "NAN" and Stats.Kills.Value == 0 and Stats.Deaths.Value == 0 then
		Number.Value = 0
	end	
end

while wait(0.1) do
	if Player ~= nil then
		if Stats ~= nil then
			local Number = (Stats.Kills.Value/Stats.Deaths.Value)
			wait(0.1)
			script.Parent.Text = "Ratio: "..Number..""
		end
	end
end

1 answer

✓ Accepted answer

Don't divide by zero. If it's zero, divide by 1.

local Number = (Stats.Kills.Value/math.max(1,Stats.Deaths.Value))

also you have two infinite while loops and the second one is never going to start because the first one is never going to finish.

1 comment

0

Thank you! It works!

This discussion is preserved as it was. New answers, comments, and votes are closed.