Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I Auto complete playernames? [Not SOLVED]

Asked by 6 years ago
Edited 6 years ago

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?

2 answers

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

I’ve made a simple script/function for you:

01function findName(input)
02    local names = {}
03    local plrs = game.Players:GetChildren()
04    for i = 1,#plrs do
05        if string.sub(plrs[i],1,string.len(string.lower(input))) == string.lower(input) then
06            table.insert(names,#names,plrs[i])
07        end
08    end
09    return names
10end

Here’s an example:
Players: Vinceberget, Sonnenroboter.

execute function:

1print(table.concat(findName("vince"),", ")

Result:

Vinceberget

Ad
Log in to vote
0
Answered by 5 years ago
01local Players = game:GetService("Players")
02function autoComplete(toComplete)
03    local matches = {}
04    for i,plr in pairs(Players:GetPlayers()) do
05        if(string.sub(1,tocomplete.length):lower() == toComplete:lower())then
06            table.insert(matches, plr.Name)
07        end
08    end
09    if(#matches == 1) then return matches[1] end
10end

Here you go! ;)

0
Can't accept my own answer... -.- Sonnenroboter 336 — 5y

Answer this question