Hello. am working on an Gui for the moderators of my game. I want that they can teleport to a player. But because some players have usernames like "jothebreadroflxddddhahahaloldie" it would be nice if they could just enter "jothebread" and the script would autocomplete that to "jothebreadroflxddddhahahaloldie". Is there any way to do that? And if theres a way: How?
COMMUNITY QUESTION
How can I Auto complete playernames? [Not SOLVED]
2 answers
I've made a simple script/function for you:
function findName(input)
local names = {}
local plrs = game.Players:GetChildren()
for i = 1,#plrs do
if string.sub(plrs[i],1,string.len(string.lower(input))) == string.lower(input) then
table.insert(names,#names,plrs[i])
end
end
return names
end
Here's an example: Players: Vinceberget, Sonnenroboter.
execute function:
print(table.concat(findName("vince"),", ")
Result:
Vinceberget
local Players = game:GetService("Players")
function autoComplete(toComplete)
local matches = {}
for i,plr in pairs(Players:GetPlayers()) do
if(string.sub(1,tocomplete.length):lower() == toComplete:lower())then
table.insert(matches, plr.Name)
end
end
if(#matches == 1) then return matches[1] end
end
Here you go! ;)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Can't accept my own answer... -.-