Using operators when assigning variables

Hello, I’ve noticed some people use OR in their script when assigning a variable like…

local a
Var = a or 1

What does it actually do?

And is it possible to apply the same concept when assigning a number variable with a limit to it without using if statements like for example, we calculate the distance of the X coordinate of an object from another object and if it is more than 15 studs then the X coordinate is set to 15?

The or operator works the same always. a or b evaluates to a if it is truthy otherwise b.

Yes you can use math.clamp for that.

local x = math.clamp(x, 0, 15)

Im new to that type of setting of variables but what I mostly do is like these

local canreload = firing == false and aiming == false and inair == false

local somethingnil;
somethingnotnil = somethingnil or 123 or 555
print(somethingnotnil) --> 123
somethingmath = somethingnotnil < 555
print(somethingmath) --> true

and sometimes you can do functions too

local _ = magnitudeNow > 200 or player:Kick()

just tryna let u know about those short codes lolololoo


Oh ok, thanks!