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

How to keep a number value from going to a negative number?

I'm trying to make a script where the Number value never goes negative but stays on 0 instead of something like -16.-

1 comment

0

Please do not submit duplicates of questions.

2 answers

✓ Accepted answer

The maximum of 0 and a number x will be 0 if x is less than 0, and otherwise it will be x.

Lua implements maximum as math.max:

x = math.max(x, 0)
0 -> 0
1 -> 1
5.9 -> 5.9
-5 -> 0
-0.01 -> 0

Please can you post the script or explain to problem a bit further.

1 comment

0

I'm trying to make an ammo script, but everytime someone reloads when the TotalAmmo(Number value) is at 2 and they need 5 for the clip, it takes the 5 so that the TotalAmmo value is -3 instead of 0 and the ammo was taken.

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