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 5 years ago
Edited 5 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 5 years ago
Edited 5 years ago

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

Ad
Log in to vote
0
Answered by 5 years ago
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! ;)

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

Answer this question