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

What is the best way to get the absolute value of a number?

I have a script that works:

X = math.random(-10,10) --this doesn't have to be math.random
if X < 0 then
    X = X*-1
end
print (X)

But I'm wondering if there is a better way, especially if I'm trying to get the absolute value of multiple numbers, possibly vector 3.

5 comments

0

I want to use this to get how far two parts are apart.

0

math.abs

0

So I just put X = math.abs(X) ? Is that right? If so that was just what I was looking for!

0

Ok I checked. It is right. Post as an answer so I can accept. Thanks!

1 answer

✓ Accepted answer
math.abs()

2 comments

0

Thanks. Always nice to get a few reputation points!

0

Thankyou, this helped greatly with my draggable inventory.

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