i would like to know how to use string.match().
lets imagine i want a script to find a part thats called hellopvppoo
and i want the script to find it, if i type hello,pvp.poo and all other words given in there.
how would i do that?
the issue is that i dont know how to use the names of instances in combination with string.match()
If you want to detect the presence of hello, pvp, and poo all independently with no regard for their position relative to each other, you can just use 3 separate calls to match.
Edit: here is an interactive thing that explains much more: https://regexr.com/
string.match() isn’t used like that, it’s used to tell if you if a specific keyword is inside a string. For example:
local match1 = string.match("Welcome to Roblox!", "Roblox")
local match2 = string.match("Welcome to my awesome game!", "Roblox")
print(match1) -- returns: Roblox
print(match2) -- returns: nil
The way to find if a specific instance using a name, is to use :FindFirstChild, so for example:
if workspace:FindFirstChild("hellopvppoo") then
print("I found hellopvppoo!")
else
print("I didn't find hellopvppoo! :(")
end
i was talking about the kind of how hd Admin knows that i mean the player called 007busterxo007 if i just type 007!
HOW does the hd admin setup do that?
I don’t think it uses match, I have made a script that replicated that in the past, and it looks like this:
function FindPlayers(name)
local usersTable = {}
for i,v in pairs(players:GetPlayers()) do
if v.Name:lower():sub(1,#name) == name:lower() then
table.insert(usersTable,#usersTable+1,v)
end
end
return usersTable
end
Function returns all players that fit the expression
It knows because out of all the players only one player’s name starts with “007”, which is what that function does. You just need to check that the length of usersTable is 1.
local selectedPlayers = FindPlayers(playerName)
if #selectedPlayers == 1 then
--Run command
else
--playerName was not specific enough, don't run command
end