Admin commands finding short name format

So I finished making my admin commands but currently i would have to type out the whole name of a player

for example i would have to do ;to ohMyGodness9

what i’m trying to do is make it so i only have to say ;to oh
i think this is supposed to be done with string.match but i’m not that good in strings

1 Like

try using string.find(PATTERN,USERNAME)
full code version
local usernameshort = “test”
for i,v in ipairs(game.Players:GetPlayers())
if string.find(v.Name,test) then
bla bla
end
end

i’m not sure of this but wouldn’t thi try to find the word “test” inside of the players name and if found continue on with the code?

give me few seconds let me hop on studio

Hello again i did this,

task.wait(5)

local command = “;to mro”
local pattern = string.sub(command,5)

for i,v in ipairs(game.Players:GetPlayers()) do
local alllow = string.lower(v.Name)
if string.find(alllow,pattern) then
warn(v.Name)
end
end

it prints out my username which is on the pattern “mro” which completes as mroofman_rblx also i added lowering so if you type ;to MroOfmAn_RbLx it still teleports to me if you should modify it so it works on your script :smiley:

wait i might of not have been so clear about what i was trying to do i’m tyring to make it so it does this but for each player so for example someone called noob12345

i would just have to do like ;to noob

( i’m not that good in stuff like this so excuse me if you allready did that)

Soo i made the example version of the code i can make a admin teleport script if you want which i can rn its so easy

making admin tp isn’t rlly the problem i just don’t understand how to use a part of a players name in a command

also if you want to split the command and the players username do:
string.sub(";to ohMyGoodness9",5) --this gives the only username change
string.find("OhMyGoodness9","OhMy") – this is for the pattern

Done i hope this helps you

game.Players.PlayerAdded:Connect(function(player) -- Player Joined A Game
	if table.find(Admins,player.UserId) then -- Check If Admin
		player.Chatted:Connect(function(msg) -- Admin Chatted
			local lowmessage = string.lower(msg) -- Lower the message
			if string.find(lowmessage,";to")  then -- Check if it has ;to command
				local victimplayer = string.sub(lowmessage,5) -- Get the player name from the message
				if string.len(victimplayer) >= 2 then -- Check if the username has more then 2 letters since if a missclick happens we don't want any bad thing happening right?
				for i,v in ipairs(game.Players:GetPlayers()) do -- Get all players from the game
					if v ~= player  then -- Check if the player we are going to teleport to is a admin if not continue
					local lowplayername = string.lower(v.Name) -- Lower Players Username
					if string.find(lowplayername,victimplayer) then -- Check Patern
						player.Character.Torso.CFrame = v.Character.Torso.CFrame -- Teleporting Weeeeeeee
						end
					end
					end 
				end
			end
		end)
	end
end)
2 Likes
local function getplyr(plr, nme)
	for _, p in pairs(game.Players:GetPlayers()) do
		if (p.Name:sub(1, #nme):lower() == nme:lower())  then
			if p.Name ~= plr.Name then
				return p
			end
		end
	end
end

Made admin before, here is what I did and still works to this day.

If you have any questions about it, ask away.

Explanation: “person” is a string value that is split up by string:split(). It is the second value in the string. Then all you do is check every player on the server and if there is a match, you change “person” to the player’s full username and send it over to the server.

My grammar isn’t the best, sorry.

for _,v in ipairs(game:GetService("Players"):GetPlayers()) do
     if v.Name:match(person) then
          person = v.Name
     end
end
local player = game.Players:FindFirstChild(person)

Should look like this.
image

Edit: This version is case-sensitive and I am yet to know how to make it not.