Fixed the issue, I had to rewrite pretty much the whole function.
local function clamp(x:number,min:number,max:number)
if x < min then
return min
elseif x > max then
return max
end
return x
end
local function textFilter(text:string, filter:number, min:number, max:number)
if filter == 1 then --only numbers
local filteredText = ""
local decimalCount = 0
for i = 1, #text do
local char = text:sub(i, i)
print(char)
if char:match("%d") then
filteredText = filteredText .. char
elseif char == '.' then
if decimalCount == 0 then
filteredText = filteredText .. char
decimalCount += 1
end
end
end
if decimalCount == 1 then
if min ~= nil and max ~= nil then
local numberToClamp = tonumber(filteredText:split(".")[1])
if numberToClamp == nil or numberToClamp == "" then numberToClamp = 0 end
local newNumber = clamp(numberToClamp, min, max)
if newNumber == max or newNumber == min then
text = newNumber
else
text = filteredText
end
end
else
local number = tonumber(filteredText)
if number then
if min ~= nil and max ~= nil then
text = clamp(number, min, max)
end
print(text)
else
text = ""
end
end
end
end
Do with the script what you will, I don’t really have time to explain it