Finding an object with "nearest name"

Hello there, Developers!

I wanted to make some of my own custom Admin Commands, and I have run across a problem. When making a give me tool command, the name must be exact to locate the tool you are searching for when using ToolsStorage:FindFirstChild(Name).

However, I have seen some Admin systems use this feature when for example I specify I want to give myself a tool with the name of "n", then the system gave me all tools starting with "n". This is of course impossible with :FindFirstChild(Name), so I am asking if someone could help me out.

Thanks in advance,
-Edryi007

Wouldn’t it just be:

local function findTool(name)

local tool = nil

 for i,v in pairs(Tools:GetChildren()) do

  if v.Name == name then

   tool = v
   break

  end
 end

return tool

end

Hmm… Lets try to do it!

local ToolStorage = script --change it if needed

local function Tool(Name : string)
	local Extract = {}
	for _, Tool : Tool in pairs(ToolStorage:GetDescendants()) do
		if Tool:IsA("Tool") then
			if string.find(Tool.Name, Name) then
				table.insert(Extract, Tool)
			end
		end
	end
	return Extract
end

1 Like

This solution works, thank you very much and have a nice day!

Im happy to help you! Have a nice day too

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.