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

Rounding Leaderstats Help please!?!

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)

1 comment

0

I need it to round, instead of it showing up as 29.833333333

1 answer

✓ Accepted answer

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

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