Auto-fill Username Script Help

Oh, yeah, my previous script that I had functioning when a button was clicked was this which defines it:

function getFullNameFromPartial(PartialName)
	local foundPlayer = nil

	local Players = game.Players:GetPlayers()
	for i = 1, #Players do
		local CurrentPlayer = Players[i]

		if string.lower(CurrentPlayer.Name):sub(1, #PartialName) == string.lower(PartialName) then
			foundPlayer = CurrentPlayer.Name
			break
		end
	end

	return foundPlayer
end

How would I define it in this script? Would I put

PlayerNameBox:GetPropertyChangedSignal("Text"):Connect(function(PartialName)

instead of

PlayerNameBox:GetPropertyChangedSignal("Text"):Connect(function()

?

Hmm, I don’t think that’s the issue, I think it’s because the PartialName isn’t defined? :sub has worked previously.

You can just define it as TextboxObj.Text

1 Like
PlayerNameBox:GetPropertyChangedSignal("Text"):Connect(function()
local PartialName = PlayerNameBox.Text
	local foundPlayer
	local Players = game.Players:GetPlayers()
	for i = 1, #Players do
		local CurrentPlayer = Players[i]
		if string.lower(CurrentPlayer.Name):sub(1, #PartialName) == string.lower(PartialName) then
			foundPlayer = CurrentPlayer.Name
			PlayerNameBox.PlaceholderText = CurrentPlayer.Name
			break
		end
	end

-- use foundPlayer variable to do the other stuff
end)

I’m on mobile so I’m not sure if this will work or not.
Edit: I dont think that PlayerNameBox.PlaceholderText = CurrentPlayer.Name would do anything since a text has already been typed also CurrentPlayer.Name can be shortened by using foundPlayer

4 Likes

So, I replace all of the PartialName s in this script to TextboxLocation.Text?

PlayerNameBox:GetPropertyChangedSignal("Text"):Connect(function()
	local foundPlayer = nil
	local Players = game.Players:GetPlayers()
	for i = 1, #Players do
		local CurrentPlayer = Players[i]
		if string.lower(CurrentPlayer.Name):sub(1, #PartialName) == string.lower(PartialName) then
			foundPlayer = CurrentPlayer.Name
			PlayerNameBox.PlaceholderText = CurrentPlayer.Name
			break
		end
	end

	return foundPlayer
end)

I’ll try this, thanks!!!

This works, but here’s what happens:

I need to click off of it and then click back on it for it to show.

^ @Jackscarlett @IEnforce_Lawz

It looks like the autofill shows up when you click off the TextBox I’m assuming? Are there any TextBox related events (Other than the GetPropertyChangedSignal) that could be intercepting that?

Thats because PlaceholderText only shows up once the textbox is empty.

I need to figure out how to override this:

If your using PlaceHolder Text then make sure to clear the .Text when it autofills.

You’ll need a textlabel under the textbox and set the textlabel’s text to the player’s name.

Hmm, but if the player’s username that it detects isn’t the right one then they won’t be able to continue typing, so that won’t work.

There would be a small problem because you can’t type anything else after that.

1 Like

Okay, hold on while I create one.

@flkfv Thank you, this worked eventually! :heart:

https://drive.google.com/file/d/1q9ieC7_OZPzfCL5EZIPxtO_0A0DlcjGQ/view

No problem! Also recommended to set the textbox and label TextXAlignment to Left or Right.

1 Like

Hello!! So, I tried it, but it didn’t work. Here is my script. Mind checking it? @flkfv

local PlayerNameBox = game.StarterGui.OrderingStart.EnterUserFrame.EnterUserTextBox

PlayerNameBox:GetPropertyChangedSignal(“Text”):Connect(function()
local PartialName = PlayerNameBox.Text
local foundPlayer
local Players = game.Players:GetPlayers()
for i = 1, #Players do
local CurrentPlayer = Players[i]
if string.lower(CurrentPlayer.Name):sub(1, #PartialName) == string.lower(PartialName) then
foundPlayer = CurrentPlayer.Name
PlayerNameBox.PlaceholderText = CurrentPlayer.Name
break
end
end
end)

local PlayerNameBox = game.StarterGui.OrderingStart.EnterUserFrame.EnterUserTextBox

PlayerNameBox:GetPropertyChangedSignal(“Text”):Connect(function()
    local PartialName = PlayerNameBox.Text
    local foundPlayer
    local Players = game.Players:GetPlayers()
    for i = 1, #Players do
        local CurrentPlayer = Players[i]
        if string.lower(CurrentPlayer.Name):sub(1, #PartialName) == string.lower(PartialName) then
            foundPlayer = CurrentPlayer.Name
            PlayerNameBox.PlaceholderText = CurrentPlayer.Name
            break
        end
    end
end)

tried making your script more readable