Auto-fill Username Script Help

Hey everyone! :wave:

I’m currently developing an Ordering System for my cafe, and I’m working on the input username GUI. Basically, I want it so when the player types in the first few letters of a customer’s username it automatically appears as the placeholdertext if it finds a player and then if they keep typing, if it’s the incorrect username it’ll keep searching the players until it displays the correct username as the placeholdertext.

Here’s an example: https://drive.google.com/file/d/1LuK5ASp_Ed08sddAWaYOtK3NKQA-Gb4Y/view

My current script is:

local text = (the location of my textbox here) -- use this for assistance with changing the placeholdertext

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
			PlayerNameBox.PlaceholderText = CurrentPlayer.Name
			break
		end
	end

	return foundPlayer
end

Let me know if you can provide any help with this, thanks! :star:

3 Likes

@JackscarIitt Could you help with this??

Oh mah gosh

You could try creating a variable for checking your if statement & print that out, to see what it results as? Possibly something like this:

local text = (the location of my textbox here) -- use this for assistance with changing the placeholdertext

function getFullNameFromPartial(PartialName)
	local foundPlayer = nil

	local Players = game.Players:GetPlayers()
	for i = 1, #Players do
		local CurrentPlayer = Players[i]
        local PlayerCheck = string.lower(CurrentPlayer.Name):sub(1, #PartialName)
        print(PlayerCheck)

		if PlayerCheck == string.lower(PartialName) then
			foundPlayer = CurrentPlayer.Name
			PlayerNameBox.PlaceholderText = CurrentPlayer.Name
			break
		end
	end

	return foundPlayer
end

Idk much about how string formulas work

2 Likes

I think it works, but the thing is I have it set to fire when the Continue button is clicked, so it’s a MouseButton1Click event. How would I make it function as the player is typing? Would I make a LocalScript under the TextBox? Also, the PlaceHolderText seems to disappear once the player starts typing. Do you know how to make it stay or will it reappear once the script fires?

You could just replace that Event with the TextBox:GetPropertyChangedSignal("Text") Event, that’ll fire every time you chat in the TextBox

1 Like

You can use .Focused to make it function as the player is typing.

EDIT: Use @JackscarIitt 's method instead

1 Like

I was gonna send this aha just for clarification :sweat_smile:

1 Like

Edit: Essentially use the GetPropertyChangedSignal then send the text to the function and it will return the best matching player.

Would this work?

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
end)

Thanks! I’ll take a look at this.

It should fire for every Text that gets added/removed in that TextBox, also yeah do refer to @IEnforce_Lawz’s post

How would I make it do so? Also, yes, I will!

It already does so, it checks when the Text changes

1 Like

This detects when text is added or removed.

1 Like

Think of it like this

Every Object has a variety of properties, if you want to detect changes from a certain property you can use the GetPropertyChangedSignal Event, then find the property you want to detect when it changes

local Part = workspace.Part

Part:GetPropertyChangedSignal("Transparency"):Connect(function()
    print("The part's transparency has changed!")
end)

wait(10)
Part.Transparency = 1

I’m getting an error:

Script:

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)

Error:

Line of script where error is:

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

@IEnforce_Lawz @THECOOLGENERATOR

Understood, thanks for the explanation!

I don’t see this defined anywhere

Print out what the conditional statement is you’re trying to check for, also try changing this to .sub?

Another issue your returning the value to nothing, you should create a function for this rather have it inside the event.