Yuari
Documentation

math.sign

Returns -1, 0, or 1 for the sign of a number.

Syntax

math.sign(x: number) -> number

Parameters

ParameterTypeDescription
xnumberValue to test.

Returns

TypeDescription
number-1, 0, or 1.

Description

Convenient for direction checks, such as turning toward a target without branching on the sign.

Only zero returns 0.

Example

local dx = target.X - part.Position.X
part.CFrame = part.CFrame * CFrame.Angles(0, math.sign(dx) * 0.1, 0)

Notes

  • math.sign(-0.0) — Returns 0.