In order to help people detect easily username of people in game i am asking how i can create a script like this?
As you can see “So” it’s the username i started write and “nostrano20” it should be what game suggest matching one of the people username in game.
My question is how can I create this effect?
So the script suggests the username based on the people in the game which can be autocompleted with Key Tab
if my request isn’t 100% clear just let me know and i will try to explain it better
I would really appreciate anyone’s help if they know how to accomplish this
--the function that determines if the keyword matches a username
local function match(keyword: string, user: string): boolean
local part = user:sub(1, keyword:len())
return part:lower() == keyword:lower()
end
local function find(keyword: string): {string}
local results = {}
--No need to make the search more sophisticated here
--This is because the players amount is never computationally significant
for _, player in pairs(game.Players:GetPlayers()) do
if match(keyword, player.Name) then
table.insert(results, player.Name)
end
end
return results
end
local function search(keyword: string): string?
local results = find(keyword)
if #results == 0 then return nil end
return results[1]
end
--run this AFTER the player instance has loaded
local keyword = "so"
local result = search(keyword)
print(keyword, result)