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

Math.Clamp, not working as expected?

This returns -1 in the output.


local myVariable = 100


myVariable = math.clamp(myVariable,0,100)

myVariable = -1

print(myVariable)

3 comments

0

Do you want it to return -1?

0

No, i'm setting the minimum value to 0, therefore it shouldn't print "-1", and i did a while loop with this aswell, and it got past the minimal value, which is 0, i don't understand.

0

The reason it prints -1 is because you are setting the variable to -1 after your other Variable

1 answer

✓ Accepted answer

It takes 3 values. X, min and max. If X is in the range between min and max it returns X. If X is lower than min it returns min and if X is higher than max it returns max.

You are setting the value to -1 after your clamp therefore it prints -1.

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