Autofill Text Help

I’m attempting to create an autofill system for usernames, and am having a bit of trouble. I have created the function that actually gets the player, and calculates all of the characters left to fill in the box, which works fine. However, I’m stuck as to how I could get it to actually fill the text in. This is what I’ve tried so far:

script.Parent.Username:GetPropertyChangedSignal("Text"):Connect(function()
	if string.len(script.Parent.Username.Text) ~= 0 then
		local player = FUNCTIONS:getPlayer()
		if player then
			local UsernameLeft = string.sub(player.Name, string.len(script.Parent.Username.Text)+1) -- gets the part of the username left
			for i = 0, #script.Parent.Username.Text do
				script.Parent.Username.Fill.Text = " "..UsernameLeft
			end
		end
	end
end)

I’m unsure as to how I could get it to actually add a space each time instead of keeping the one.

local f, g, u
script.Parent.Username:GetPropertyChangedSignal("Text"):Connect(function()
    if string.len(script.Parent.Username.Text) ~= 0 then
    	local player = FUNCTIONS:getPlayer()
    	if player then
    		u = string.sub(player.Name, string.len(script.Parent.Username.Text)+1) -- gets the part of the username left
    		f = string.len(script.Parent.Username.Text)
			g = table.create(f, " ")
			script.Parent.Username.Fill.Text = table.concat(g) .. u
    	end
    end
end)
1 Like

Hmm. It worked, however, with different usernames it can look awkward. image
Is there another way to do this instead of having two separate TextBoxes and TextLabels and just filling in the rest?

You can change a TextLabel position with this

2 Likes

I know this post is old but you could also use the text box’s property PlaceHolderText and that might work too.

3 Likes