Can't use Bullet symbol in TextBox

Hello, I’m trying to create a script that censors a TextBox text with a Bullet symbol (•). Only for some weird reason, it isn’t working as I intended

Here’s my script:

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

But, after typing only one character I get this mess:
image
Together with an error:

Maximum event re-entrancy depth exceeded for Instance.TextChanged

Please help, thanks.

2 Likes

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

1 Like

It doesn’t give an error but the weird mess of characters still appear…

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.

dont use a debounce. that is a silly solution

2 Likes

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.

This still didn’t help with my main problem, the weird mess of characters.

Again, this is still here image after just typing one character.

I would use Swag’s solution:

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.

1 Like

I’ve tried that solution but still no result, the error is gone but there’s still the same weird X after a few characters inputted.

This is my current code:

local UpperText = script.Parent.Parent.InputField:FindFirstChild('Text')

script.Parent:GetPropertyChangedSignal('Text'):Connect(function()
	UpperText.Text = string.sub(string.rep('•', #script.Parent.Text), 1, 20)
end)

This might be far fetched, but try changing the dot string to “\226” including the quotation marks. This is the character code for the dot.

1 Like

“\266” gives the image character again, wasn’t the Unicode for the Bullet 2022?

I was hoping as a far-fetched idea you could get the bytecode of the bullet and re-create it that way.
image

image

So here’s the problem:
image
You’ll notice that is far less than 20 characters, and the X icon is there.

Lua’s substring works on bytes - however, this bullet character is multiple bytes:
image

20 / 3 = 6.66
So, you are cutting off the last bullet.

Instead, you must use substring in multiples of 3, like so:
:sub(1, 20 * 3)

Whatever you limit it to must be divisible by 3.
Does this clear everything up?

1 Like

It does, I never knew that. Thanks for the information, I’ll just quickly check if that works.

1 Like