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

How do I set a max value for a numbervalue?

Does anyone know how to set a max value for a number value? I’ve tried a few pieces of code but none of really worked

1 answer

There isn't any property of NumberValue that let's you do this, but remember that there's an event called Changed for this object that fires whenever its value is changed. So with this is mind, simply connect a function to the event that checks if the new value is above the maximum, and if it is, lower it to the max.

local max = 100

local numberValue = Instance.new("NumberValue")
numberValue.Parent = workspace

numberValue.Changed:Connect(function(value)
	if value > max then
		numberValue.Value = max
	end
end)

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