How do I make it so I don't have to type a player's full name?

I want to make it so I don’t have to type the player’s full name for my admin script. How would I do this?

1 Like

string.match should do the job.

Example:

local Word = "Roblox"
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(plr)
     plr.Chatted:Connect(function(msg)
        if msg:match(Word) then
           --do code
        end
    end)
end)

When checking for player, you might need to use a for loop and check if there is a match found.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(plr)
     plr.Chatted:Connect(function(msg)
      for _,Player in pairs(Players:GetPlayers()) do
          if msg:match(Player.Name) then
          end
      end
   end)
end)
1 Like

u could use sting:find().

Here is a example:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(plr)
   plr.Chatted:Connect(function(msg)
      for _,Player in pairs(Players:GetPlayers()) do
          if plr.Name:find(msg) then
          end
      end
   end)
end)
1 Like
local Players = game:GetService("Players")

for i, player in pairs(Players:GetPlayers()) do -- Get all players
		if player.Name:lower():sub(1, #args[1]:lower()) == args[1]:lower() then -- Get player from few characters. (Example: My username is "TaxFraudBruh" and you get that just from "tax"
				-- Your code
		end
end

What I do is create a table called suitable matches, then use string.find to check what players match the arguments provided. The one that’s closest would be inserted to the table.

Sample:

local suitableMatches = {}

		for i, player in ipairs(Players:GetPlayers()) do
			local playerName = string.lower(player.Name)

			if playerName == target then
				suitableMatches = {player}
				break
			elseif string.find(playerName, target, 1, true) then
				table.insert(suitableMatches, player)
			end
		end

		players = {suitableMatches[1]}
	end