Hello! I am here to ask an age-old question, how do I auto-complete a name in a textbox?
I thought I had formed a small base, just to find someone’s name, however even this isn’t working!
Here is the code that I attempted:
script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
local text = string.match(script.Parent.Text, game.Players.LocalPlayer.Name)
local text1 = tostring(text)
print(text1)
script.Parent.Text = (text1)
end)
Capture the text and see if it is currently matching with the first 3-5 characters of the player’s name, if it is, replace the text entirely with the player’s name.
You may as well as use string:lower() to be friendly towards case sensitive characters in their username or the text it self.
script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
if (game.Players.LocalPlayer.Name:lower():sub(1, 4) == text:lower():sub(1, 4) then
script.Parent.Text = game.Players.LocalPlayer.Name
end
end)
``
No, it wouldn’t. Your description: “just to find my name,”. Anyways, what you can do is grab the players in the game and add their name to an table when the text is changed and check if the first 1-4 characters of their text matches any name inside that table.
Demonstration:
local players = {}
local diff = 0
local input
script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
for _, player in ipairs(game.Players:GetPlayers()) do
players[player.Name] = player.Name
end
for _, name in pairs(players) do
input = script.Parent.Text:sub(1, 5)
if (input == name:sub(1, 5) ) then
script.Parent.Text = name
break
end
end
end)
It doesn’t seem to be working, no errors, it just doesn’t match the text.
local players = {} -- Create a table
script.Parent:GetPropertyChangedSignal("Text"):Connect(function() -- start when the text is changed
for _, player in ipairs(game.Players:GetPlayers()) do -- get a list of all players
players[player.Name] = player.Name -- absolutely no clue
end
for _, name in pairs(players) do
if (script.Parent.Text:lower():sub(1, 4) == name:sub(1, 4)) then -- if the text upto 4 characters matches then
script.Parent.Text = name -- change the text
break
end
end
end)