Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to add a Kill Death Ratio to a DataStore?

Asked by 6 years ago
Edited 6 years ago

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?

0
This is an integer underflow. I would assume it's something to do with the value of Deaths being 0. Griffi0n 315 — 6y
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. Rallient 40 — 6y

1 answer

Log in to vote
0
Answered by
Smaltin 46
6 years ago
Edited 6 years ago

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
0
I still get the same huge number, not for sure why it won't work. Rallient 40 — 6y
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. lunatic5 409 — 6y
Ad

Answer this question