I know you can only do this with strings but is there a way to find a player from someone typing their name partially?
Is there a way to format a list of all the players as a string and then find the one you need
For example:
string = {player1,player2} string.find(string,1) print(the value with '1' in it)
finding a way to find a player by partial is relatively easy:
function findPlayer(msg) local msg = msg:lower() for _, v in pairs(game.Players:GetPlayers()) do local name = v.Name:lower():sub(0, msg:len()) if name == msg then return v end end return nil end
This works in the example:
function findPlayer(msg) local msg = msg:lower() for _, v in pairs(game.Players:GetPlayers()) do local name = v.Name:lower():sub(0, msg:len()) if name == msg then return v end end return nil end game.Players.PlayerAdded:Connect(function(player) player.Chatted:Connect(function(msg) print(findPlayer(msg).Name) end) end)
you can use string.match()
to find a specific character or word inside a string. Such as this example:
--client local TextBox = script.Parent -- lets say the script was located inside the textbox TextBox:GetPropertyChangedSignal("Text"):Connect(function() for _,player in pairs(game.Players:GetPlayers()) do local lower = string.lower(TextBox.Text) local lowerplayer = string.lower(player.Name) if string.match(lowerplayer,lower) then -- if the player name has a word or letter inside the string then print(player.Name) -- prints the player's name end end end)
string.lower()
turns the string specified letters to lowercase, since string.match() also includes capital and lowercase letters too. :GetPropertyChangedSignal()
fires when the property inside the parentheses changes.