What I mean:
When you type "Magic", it finds the player who starts with "Magic" and goes to "Magicboopoo".
How do I do this?
I want to complete my admin GUI with new features. And this is one I've hoped for for a while.
What I mean:
When you type "Magic", it finds the player who starts with "Magic" and goes to "Magicboopoo".
How do I do this?
I want to complete my admin GUI with new features. And this is one I've hoped for for a while.
You can use string patterns to accomplish this. All you need to do is loop through all the players in the game and check to see if there is a substring (anchored to the beginning using the ^ anchor) that matches what was given. It may also be convenient to ignore case using the lower method in the string library.
Example assuming you are in the game:
local function getPlayerFromSubstring(substring)
for _, player in ipairs(game.Players:GetPlayers()) do
if string.lower(player.Name):match("^"..string.lower(substring)) then
return player
end
end
return nil
end
print(getPlayerFromSubstring("Magic"))
-- Output: Magicboopoo
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
deleted comment lol