Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to add a text cap/limit to a text import?

Asked by 6 years ago

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:

1local Text = script.Parent
2Text.Changed:connect(function()
3    Text.Text = Text.Text:sub(1,50);
4end);

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

0
put a print in the function and test if it prints awesomeipod 607 — 6y
0
it doesnt print oshawat00 62 — 6y
0
This is a really great question, I’d like to know too Ziffixture 6913 — 6y
0
This code is in a local script right? hellmatic 1523 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago

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:

01local UIS = game:GetService("UserInputService")
02 
03local TextButton = script.Parent
04 
05local MaxCharacters = 50
06local InputBeganConnection = nil
07 
08local 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
View all 33 lines...
Ad

Answer this question