How do you set a characters limit on a textbox?

Clearly, there is an issue from another topic like this, three years ago and it won’t work even now. Take a look at this and see what we can change?

	script.Parent.Text = script.Parent.Text:sub(1,16)	

You should try this:

	if string.sub(script.Parent.Text,1,16) then
		print("Over the limit")
		script.Parent.Text = string.sub(script.Parent.Text,1,16)

Unfortunately, it didn’t worked. @waterrunner

I would end up something like this. Sorry!

It looked like the original script would have worked. Can you put a print inside that function to make sure that it’s running at all? If it is, then something should be written in the output window. Otherwise the problem might be that the script isn’t running at all or it’s at the wrong place.


Here’s a little revision that should work:

    	if string.len(script.Parent.Text) > 16 then
    		print("Over the limit")
Local text = string.sub(script.Parent.Text,1,16)
script.Parent.Text = nil
    		script.Parent.Text = text

@Alpha_Triztin This should also be placed in the TextBox itself as it’s using script.Parent

1 Like

This script seems to working fine (the script wasn’t edited at all) when tested in Studio with the following hierarchy:
Working example:

As @XAXA said, the problem might be that the script isn’t running at all or it’s at the wrong place. You should also check if the script is a LocalScript as server scripts cannot observe or change any descendant of PlayerGui (they exist only on the client).


That looks like it works fine. Also thx, imma use this in my games.

@Doglord120 It is.
@XAXA However, it just doesn’t show up on output. I can’t do GIF showing. But, I know that it wouldn’t show even when it is an output.

Is this not in a local script then? If it’s not, this code should be in a localscript. The server should never know about or touch interface and input.

You also need to give more description other than a generic “it doesn’t work”

@PirateOnThePlank It followed like that, however, it still won’t work. Another idea?

Did it stop you from writing more text?

Here’s a proof of the property.

Remember that the GUI gets cloned to the player.

Property of LocalScript

  • Name: CharLimit
  • Disabled: False
  • Parent: Input

There was no stopping, It was endless.

As I forgot to mention about this issue, it appears that Roblox may have did something from a year ago that I’ve had an issue when I wasn’t a member of the Devforum about this, it may have stopped working because of the functions, I think. What do you guys think?

Try the code I posted. Let’s see if that’ll do anything.

Oh, I did follow it. However, it acted like the same with the other people’s idea. It won’t work. Strange… @Doglord120

Would you happen to have a link that mentions said change?

I don’t know about it. It may have Roblox changed something with their functions. But I never know since there is a lot of changelogs like 100+ which is partically one of them. I don’t want to look through them. However, it did affect the issue with the function Change.

I made a revision to the revision. Let’s make this work.

What do you mean? I clearly don’t understand what you’re saying.