script.Parent.TextBox:GetPropertyChangedSignal("Text"):Connect(function() for _,v in pairs(game.Players:GetPlayers()) do if string.match(script.Parent.TextBox.Text, v.Name) then print(v) end end end)
It only returns v if I write the full name, when I want it to match the first words in a string. How would I fix it so that it auto completes if I start writing a name?
The first parameter is the string, the second is the pattern you are looking for. It should be the player's Name
first and the TextBox.Text
second.
string.match(plr.Name, TextBox.Text)
string.match will match anywhere in the string. string.match('helloPizza', 'Pizza') will return something. Use string.sub to stop this interaction.
string.match is case sensitive. By making the string lowercase/uppercase, it'll compare just the letters rather than checking if upper/lower letters are matching.
local lowerName = plr.Name:lower() local lowerText = TextBox.Text:lower() string.match(lowerName, lowerText)
Having the string be nothing ""
will match with any player. You should check if the TextBox.Text
is not equal to ""
before running anything. Since you are autofilling, don't think this matters.
Since people could have similar names, you should not autofill until there is only one person that matches the string.
TextBox:GetPropertyChangedSignal("Text"):Connect(function() local matchedPlayers = {} for _,v in pairs(game.Players:GetPlayers()) do if string.match(v.Name:lower(), script.Parent.Text:lower()) then table.insert(matchedPlayers, v) end end if (#matchedPlayers == 1) then local autofill = matchedPlayers[1] end end)
Good luck!
script.Parent.TextBox.Changed:Connect(function() for i,v in pairs(game.Players:GetChildren()) do if v.Name:match:(script.Parent.TextBox.Text:lower()) then print(v) end end end)
I believe this will work, it checks the players name when the text box text is changed and lowercases it. Wrote this on my phone so it might not be fully right (typos)