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

Rounding Leaderstats Help please!?!

Asked by 9 years ago

So I'm trying to make my Mana round up from 0.5 or down from 0.49 and this current script doesnt work to round it?

P = script.Parent.Parent

while true do
    wait(1)
 P.bin.Mana.Value = P.bin.Mana.Value + (P.bin.MaxMana.Value / 120)
P.bin.Mana.Value = math.floor(P.bin.Mana.Value + 0.5)
    end

The error is in this part

P.bin.Mana.Value = math.floor(P.bin.Mana.Value + 0.5)
0
I need it to round, instead of it showing up as 29.833333333 attackonkyojin 135 — 9y

1 answer

Log in to vote
2
Answered by
Unclear 1776 Moderation Voter
9 years ago

You are using a NumberValue instead of an IntValue. NumberValues are not guaranteed to give you integer values. If you want integer values, use IntValues.

Assuming you replace the two, here is your code but cleaned up and with proper rounding now that you can't set the intermediate calculation to the value.

local target = script.Parent.Parent
local manaValue = target.bin.Mana

while true do
    wait(1)
    local newValue = manaValue.Value + (manaValue.Value / 120)
    manaValue.Value = math.floor(newValue + 0.5)
end

Ad

Answer this question