I've been looking everywhere on scripting helpers and I only found one answered question that was made 2 or more years ago and the script includes:
1 | local Text = script.Parent |
2 | Text.Changed:connect( function () |
3 | Text.Text = Text.Text:sub( 1 , 50 ); |
4 | end ); |
I edited it to make the cap 6 by changing the 50 to 6 however it doesn't work and it just allows the user to keep applying text. I was wondering if this script is too old and not working or if it's not supposed to be used in the context I want it or in the wrong script. (At the moment I'm using the standard script.) If anyone could help me that would be a huge help to the game I'm trying to make. ~ oshawat00
Since the Changed
event method didn't work, we would have to detect when the client presses a key on the keyboard. We could do this using InputBegan
, an event from UserInputService:
01 | local UIS = game:GetService( "UserInputService" ) |
02 |
03 | local TextButton = script.Parent |
04 |
05 | local MaxCharacters = 50 |
06 | local InputBeganConnection = nil |
07 |
08 | local function DisconnectInputBeganEvent() |
09 | -- since events can be connected, you can cancel it by disconnecting |
10 | -- it is important in this case since we reconnect the event when the TextButton gains focus. |
11 | -- it'll stop events from stacking and allows us to cancel them when they're unneeded |
12 | if InputBeganConnection then |
13 | InputBeganConnection:Disconnect() |
14 | InputBeganConnection = nil |
15 | end |