Ah. When you change the text, it will fire this event, which will change the text, which will fire this event. This leads to an infinite loop that can lead to the error you are having. Try using a debounce
local debounce = false
script.Parent:GetPropertyChangedSignal('Text'):Connect(function()
if debounce == false then debounce = true
script.Parent.Text = string.rep('•', #script.Parent.Text)
if string.sub(script.Parent.Text, 1, 20) then
script.Parent.Text = string.sub(script.Parent.Text, 1, 20)
end
wait()
debounce = false
end
end)
When the event fires, the debounce will prevent the event from running the code again until it has changed the text, so it wont loop
make a text box and have its text be invisible. Then make a text label and have its text be visible. This will prevent any weird re-entrancy depth errors you get.
If it wasn’t for limitting this to 20 chars, it would’ve fired 200 times before erroring out.
So you won’t get an error here.
The debounce in this case is happening so fast that it is ignored. The .Changed event fires on the next script cycle, while the debounce is disabled this cycle. Add wait() before Debounce = false
I agree with @SwagMasterAndrew’s solution below, rather than a debounce in this case.
Make the text of the TextBox invisible, then add a TextLabel’s on top of it.
Then, use your original code, except instead of changing the TextBox’s text, change the TextLabel’s text instead.
This will also help you with being able to accurately read what the actual text is in your code (the TextBox’s text will be the original text), while displaying to the user the dots.
Then, you don’t have to change the TextBox’s text at all, you can just convert it to dots and display it on the TextLabel. It’ll accomplish the same thing without having to worry about max re-entry depth, debounces, or anything like that. It greatly simplifies the code.