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

Math.Clamp, not working as expected?

Asked by 3 years ago

This returns -1 in the output.


local myVariable = 100 myVariable = math.clamp(myVariable,0,100) myVariable = -1 print(myVariable)
0
Do you want it to return -1? Zelt3q 31 — 3y
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. ZOOP1015 44 — 3y
0
The reason it prints -1 is because you are setting the variable to -1 after your other Variable Zelt3q 31 — 3y

1 answer

Log in to vote
0
Answered by
Zelt3q 31
3 years ago

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.

Ad

Answer this question