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

How to change a TextBox's text into asterisks, like a password textbox?

Asked by 5 years ago
Edited 5 years ago

Here is an example, https://gyazo.com/cf1a8d5960cb3c0f5204d0ffba81094c, the game can be found here, https://www.roblox.com/games/560789612/Riscord-UI-v0-1-5, I have been trying to figure out how to do something like this for a while but I can't figure out how to, would appreciate some help, thank you.

1 answer

Log in to vote
0
Answered by
lolzmac 207 Moderation Voter
5 years ago
Edited 5 years ago

The number of characters in a string can be counted using #string, so we can use this to iterate through each character in the string, replace it with an asterisk, and repeat until we get to the end. After that, just replace the TextBox text with the string we just made. We'll use the FocusLost event to update the text.

TextBox = script.Parent
local replacer = "*"

TextBox.FocusLost:Connect(function()
    local string = TextBox.Text
    local newString = ""
    for i = 1, #string do
        newString = newString .. replacer
    end
    TextBox.Text = newString
end)

Strings wiki post

FocusLost event

Ad

Answer this question