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

How to add a Kill Death Ratio to a DataStore?

I'm a bit confused on how exactly I would do this. I have the rest of my DataStore fully functioning, but this is the only part I'm not so sure about.

	local KDR = Instance.new("NumberValue", StatNumbers)
	KDR.Name = "KDR"
	if Kills.Value == 0 and Deaths.Value == 0 then
		KDR.Value = 0
	elseif Kills.Value >= 0 and Deaths.Value > 0 then
		KDR.Value = Kills.Value/Deaths.Value
	elseif Kills.Value > 0 and Deaths.Value == 0 then
		KDR.Value = Kills.Value
	end

When I go to view my stats and the output, I get this number: -2147483648 I have my Kills set to 28 whilst my deaths are set to 3, so I was expecting a number around 9.3. What should I change to fix this?

2 comments

0

This is an integer underflow. I would assume it's something to do with the value of Deaths being 0.

0

Yeah I understand that, but I'm just confused because what if you have 1 kill and 0 deaths? The KDR should be 1 and I have no idea on how to get the program to understand that. Just like how any normal KDR is; Kills divided by Deaths.

1 answer

You don't need to divide the kills by 0, so just put the kills.

local KDR = Instance.new("NumberValue", StatNumbers) 

KDR.Name = "KDR"
if Kills.Value == 0 and Deaths.Value == 0 then
	KDR.Value = 0
elseif Deaths.Value > 0 then
	KDR.Value = Kills.Value/Deaths.Value
else
	KDR.Value = Kills.Value
end

2 comments

0

I still get the same huge number, not for sure why it won't work.

0

Extremely late, but you need to use math.floor to round it down. kill death ratios tend to go up to the 2nd decimal place (AKA the hundredths place), so you would round it down to that.

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