ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. math.clamp

Function

math.clamp

Server and clientMath, vectors and matricesTrilogy Hub only

Clamps a number to the range from lo to hi.

Syntax

math.clamp(value, lo, hi)

Arguments

valuefloat
The number.
lofloat
Lower bound.
hifloat
Upper bound.

Returns

The clamped number.

Example

addCommandHandler("hp", function(player, cmd, amount)
    setElementHealth(player, math.clamp(tonumber(amount) or 100, 1, 100))
end)