How Would I use math.Clamp when adding/subtracting to values

I have tried to use the math.Clamp function but I’m quite confused as it does not constrain my int value. I need a way to set a maximum and minimum number so the int value cannot go above or below the number.

This is what I have tried so far

page.Value = page.Value + math.clamp(1,0,2)
1 Like

In your code, math.clamp(1,0,2) clamps the number literal constant 1 as this is placed in the first (named “n”) argument rather than the IntValue so it does not constrain the IntValue as expected.


You need to clamp the entire thing:

page.Value = math.clamp(page.Value + 1, 0, 2)

Your current code clamps 1 between 0 and 2 which is just 1 since 1>0 and1<2.

1 Like

Thanks this makes sense now ty for the help

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.