Terribly explained but I’m working on a report user system which relies on checking if the user from the first field is actually ingame, bit of it would be this
elseif not game:GetService("Players"):FindFirstChild(fieldOneInput) then
pcall(fieldOneFail)
it does fieldOneFail even though the user is ingame, but the name is just different lower/upper case, how woud I make it so it doesn’t matter whether it’s upper or lower case so you don’t have to be exact for it?
You can create an array with all of the players names in it which have been converted to lower case, and then search through that table to see if theres any matches using either table.find or your own function.
What you would want to do is create a variable called Found, and then loop through the players and if found, set it to true (or the player that was found). Then after the loop is done, check if the variable is true, if not, then do the fail thing.
Like so:
local found = false
for k, v in pairs(game.Players:GetPlayers()) do
if v.Name:lower() == input:lower() then
found = v
break
end
end
if not found then
pcall(fieldOneFail)
end
local Players = game:GetService("Players")
local fieldOneInput = "PlayerName"
function short(array)
local result = {table.unpack(array)} --copy the array
table.sort(result, function(a, b)
return a:len() > b:len()
end)
return result
end
function getPlayers(text)
local results = {}
for i, player in pairs(Players:GetPlayers()) do
if string.find(player.Name:lower(), text:lower()) then
table.insert(results, player.Name)
end
end
return results
end
local found = getPlayers(fieldOneInput)
for i, v in pairs(found) do
print(v)
end
--short actual names based on their length
local shorted = short(found)
local best_matching = shorted[1]
local less_matching = shorted[#shorted]
print(best_matching, less_matching)