How could i make it so that instead of referencing a player name in, for example, a chat command i just have to say the first few letters of their user?
Example:
Player username: Oggy5000
Instead of “/bring Oggy5000” just “/bring Og”
How could i make it so that instead of referencing a player name in, for example, a chat command i just have to say the first few letters of their user?
Example:
Player username: Oggy5000
Instead of “/bring Oggy5000” just “/bring Og”
function FindPlayer(String)
for i,v in pairs(game:GetService("Players"):GetChildren()) do
if (string.sub(string.lower(v.Name),1,string.len(String))) == string.lower(String) then
return v
end
end
end
This would cause silent “collisions” picking the first player at random that matches, for instance if you have two players name “Oggy500” and “ogFrog” it could select either one at random.
Something to aware of, but cannot be easily fixed.
function FindPlayers(String)
local t = {}
for i,v in pairs(game:GetService("Players"):GetChildren()) do
if (string.sub(string.lower(v.Name),1,string.len(String))) == string.lower(String) then
table.insert(t, v)
end
end
return t
end
Quickly altered the snippet above to return an array of players.