Valoare:GetPropertyChangedSignal(“Text”):Connect(function()
Valoare.Text = Valoare.Text:gsub(“%D+%P+”, “”)
if tonumber(Valoare.Text) > 1 then
Valoare.Text = “1”
end
end)
I kind of want it to not be able to go over 1, it works but once i type something like 0.7 it goes back to one because there is a value higher than 1.
How can I fix this?
You probably want to use the math.clamp function or if you want to allow negative numbers, the math.min function. You need to convert the text to number, clamp it and then put it back in the text box.
local Min = 0
local Max = 1
local Default = 0
local Safety = true
Valoare:GetPropertyChangedSignal(“Text”):Connect(function()
if (Safety) then -- Prevent crashing the game.
local n = tonumber(Valoare.Text) or Default
Safety = false
Valoare.Text = math.clamp(n, Min, Max)
Safety = true
end
end)