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.Changed:Connect(function()
	script.Parent.Text = script.Parent.Text:sub(1,16)	
end)
8 Likes

You should try this:

script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
	if string.sub(script.Parent.Text,1,16) then
		print("Over the limit")
		script.Parent.Text = string.sub(script.Parent.Text,1,16)
	end
end)
3 Likes

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.

2 Likes

Here’s a little revision that should work:

    script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
    	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
    	end

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

2 Likes

This script seems to working fine (the script wasn’t edited at all) when tested in Studio with the following hierarchy:
image
Working example:
https://gyazo.com/eb882d69becc452a8a3c6db7e2a93306

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).

11 Likes

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.