Add max value and min value

I made a script where basically, if you set a value over 3 on a textbox, its set to 3.
and if the values under 0.5, its text is 0.5

but it didnt work, anyway methods i can try?
i used this script:

local minval = 0.5
local maxval = 3

local val = script.Parent

val:GetPropertyChangedSignal("Text"):Connect(function()
	if minval <= 0.5 then
		val.Text = 0.5
	end
end)

val:GetPropertyChangedSignal("Text"):Connect(function()
	if maxval >= 3 then
		val.Text = 3
	end
end)

You might want to put this under #help-and-feedback:scripting-support

Here’s a better code for your code:

--customize this however you want
local minval = 0.5
local maxval = 3

local val = script.Parent

val:GetPropertyChangedSignal("Text"):Connect(function()
    local enteredValue = tonumber(val.Text) --turn the text into a number

    if enteredValue and enteredValue < minval then --doing what you asked for
        val.Text = minval
    elseif enteredValue and enteredValue > maxval then
        val.Text = maxval
    end
end)

What you did not right is you compared a variable to a number, not the text with the variable.

    -- here we check if enteredValue is not nil to prevent errors, then we check if the enterValue is smaller than the minval, and so for the maxval, if it's larger than it.
    if enteredValue and enteredValue < minval then
        val.Text = minval
    elseif enteredValue and enteredValue > maxval then
        val.Text = maxval
    end

sorry for the late response, i didnt get a notification.
thanks for the help!

im also kinda new to the forum since i deleted my old account and left it for a while.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.