You can write your topic however you want, but you need to answer these questions:

What do you want to achieve?
A not reversed math.clamp()?

What is the issue?
Basically I’m making a code that calculates engine RPM (Revolutions/Minute) and I clamped it, but the min and max seems to be flipped?

What solutions have you tried so far?
Tried flipping the min and max but that just returns an error.

local function getEngineRPM(currentSpeedinRPS : number)
local FULL_CIRCLE = math.pi * 2
local MINUTE = 60
local RPM = FULL_CIRCLE/(currentSpeedinRPS * MINUTE)
return RPM * 1000
end
local function getSPStoRPS(currentSpeedinSPS : number)
local speedInMeter = currentSpeedinSPS * 28/100
local radiusInMeter = wheelRadius * 28/100
local calculations = speedInMeter/radiusInMeter
-- Same concept as ω = v/r
return calculations
end
local rpm = getEngineRPM(getSPStoRPS(engineSpeed))
script.RPM.Value = math.clamp(rpm, 700, 7000)

This is the formula for RPM: RPM = (Linear Speed / (π × Diameter)) × 60

Try doing:

local function getSPStoRPM(currentSpeedinSPS : number) -- Removed conversion to meter as it would just cancel each other out.
return currentSpeedinSPS/(math.pi*2*wheelRadius) * 60
end
local rpm = getSPStoRPS(engineSpeed)
script.RPM.Value = math.clamp(rpm, 700, 7000)

Put a print in here to tell you what the number actually is. It might point out if you messed up the calculation by a decimal place or 2, or if the number is half of what you expect, indicating you need to go back and change your formula.

print(rpm) -- if the number isn't what you figured it is then go back to your calculations.
script.RPM.Value = math.clamp(rpm, 700, 7000)

I’m pretty sure that the formula @K4ttt_i gave is correct. You just seem to have an unrealistic min. I don’t know what exactly your wheel radius is but if I calculated correctly, then with a wheel radius of 1, the speed in studs per second would need to be more than 73 in order to reach 700 RPM. If wheel radius is greater than 1, then an even bigger speed would be needed for 700 RPM.

My RPM was too high that’s why the clamping reverses but now I use this

local function getSpin(currentSpeedinSPS : number, radius : number)
local speed = currentSpeedinSPS
local radius = radius
local calculations = speed/radius
local circumference = (math.pi * 2) * radius
local wheelSpeed = (currentSpeedinSPS/60)/circumference
return wheelSpeed
end