Auto-fill Username Script Help

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 @Jackscarlett '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.

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.