Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can i make a number cap for a textbox?

I have made a textbox so u can only put numbers in it and how would i make it so you can only go up to a certain number.

Right now i have

if script.Parent.Text < 60 then
	script.Parent.Text = 60
	end

it returns Players.TeaWithMee.PlayerGui.RaceSelector.Menu.SliderMenu.BBox.LocalScript:1: attempt to compare string and number

how would i make it so it returns back to 60

2 answers

--###----------[[VARIABLES]]----------###--
local TextBox = script.Parent


TextBox.FocusReleased:Connect(function(EnterPressed)
    if not (EnterPressed) then return end
    ---------------
    local Text = TextBox.Text
    ---------------
    if (Text:match("^%d+$") then
        ---------------
        TextBox.Text = (tonumber(Text) > 60 and "60" or Text)
    end
end)

I'm maybe confused on the request but, you could just treat the Text value as a number.

local par = script.Parent
if tonumber(par.Text) < 60 then
    par.Text = '60'
 end

2 comments

0

It returns the same error

0

And what i mean is if someone puts in a number above 60 in a text box i want to return back to 60 instead of a higher number

This discussion is preserved as it was. New answers, comments, and votes are closed.