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)
--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