so the title explains it all. So basically the textbox can only be written in numbers and the lowest is can go is 0 and the highest it can go is 250.
local textBox = script.Parent
textBox:GetPropertyChangedSignal("Text"):Connect(function()
textBox.Text = textBox.Text:gsub("%D", "")
if tonumber(textBox.Text) < 0 then
textBox.Text = 0
elseif tonumber(textBox.Text) > 250 then
textBox.Text = 250
end
end)
local textBox = script.Parent
textBox:GetPropertyChangedSignal("Text"):Connect(function()
textBox.Text = textBox.Text:gsub("%D", "")
textBox.Text = math.clamp(0, 250, tonumber(textBox.Text))
end)
what does clamp do?
Empty space
math.clamp takes three arguments, the first represents the lower limit of the clamp, the second represents the upper limit of the clamp and the third represents the value being clamped, if the third value is less than the lower limit then the lower limit is returned, if the third value is more than the upper limit then the upper limit is returned and finally, if the third value is between the two limits then the third value is returned itself.
I recommend using the string table instead of the oop
local s = os.clock()
for i = 1, 100000 do
local x = ("string"):sub(1,4)
end
print(os.clock()-s) -> 0.04021599999963655
local s = os.clock()
for i = 1, 100000 do
local x = string.sub("string", 1, 4)
end
print(os.clock()-s) -> 0.022279999999227584
Edit: with barely noticable difference. I dont think it really matters
Iām aware of the minor (negligible) time improvement as you circumvent the need to index the string object for the method but stylistically I prefer calling string library functions as instance methods.