Is there a way to limit users to type a certain amount of characters into a textbox?

I’m making a computer system in Studio right now, and I’m trying to allow the user to create their own in-game computer account, and I want to limit the amount of characters a player can type into a textbox, is there a possible way of doing so?

2 Likes

you can do

TextBox:GetPropertyChangedSignal("Text"):Connect(function()
TextBox.Text = TextBox.Text:sub(1, put how much is the limit it must be a number)
end)
2 Likes

How to check how many letters are there in TextBox? - Help and Feedback / Scripting Support - DevForum | Roblox

1 Like

Try this:

-- in the text box
local TEXTBOX = script.Parent

TEXTBOX.Changed:Connect(function()
      local __len__ = string.len(TEXTBOX.Text) 
if __len__ >= limit then
TEXTBOX.Text = "Max character"
end
end)

string docs here: string (roblox.com)

1 Like

This does work, however how do I make it so that if there is less than a certain number, say 3, it’ll give a warning?

Im gonna guess what warning is like a GUI with a text what say warning or something
And its connected by a remote

-- in the text box
local TEXTBOX = script.Parent

TEXTBOX.Changed:Connect(function()
      local __len__ = string.len(TEXTBOX.Text) 
if __len__ >= limit then
TEXTBOX.Text = "Max character"
game.ReplicatedStorage.WARNINGSS:FireServer()
end
end)

WARNINGSS is the remote what fire the remote what have warning
(I know what i explain ultra bad)

-- WARNINGSS
game.ReplicatedStorage.WARNINGSS.OnServerEvent:Connect(function(plr,arg)
      game.ReplicatedStorage.WARNINGCS:FireClient(plr,arg)
end)

you can remove the “arg” if you dont needed

This is the script what is the other side of the max limit characters (Instead of max is min)

-- in the text box
local TEXTBOX = script.Parent

TEXTBOX.Changed:Connect(function()
      local __len__ = string.len(TEXTBOX.Text) 
if __len__ <= limit then -- you can remove the "=" if you need its just less than limit and not the same of limit
TEXTBOX.Text = "Max character"
game.ReplicatedStorage.WARNINGSS:FireServer()
end
end)

Heres is some useful links:
TextBox (roblox.com) TextBox
Operators (roblox.com) Operators like “<”, “>”,"==",ect,ec

2 Likes

Thanks so much for your help, I’ll try this out and will tell you if it works!