Find Item with a special text part

So the script to find an item in the character called “Something”…“Item” so It could be “MostPowerful”…“Item” or “LeastPowerful”…“Item”. So I want the script to find some text and Item on the end so another example of an item name “MostPowerfulItem”

Code I have tried to get it to work with

character:FindFirstChild("".."Item")

But it’s just getting nil how do I do it in another way?

Your current code is simply concatenating an empty string with “Item” so it’s only just searching for “Item”.

My solution would be to put the different names in an array, iterate through until you find it:

local names = {"MostPowerful", "LeastPowerful"};

for _, name in ipairs(names) do
    local item = character:FindFirstChild(name .. "Item");

    if (item) then
        --// Code
        break; --// You can remove this if you want to continue searching for others
   end
end
1 Like

One of the functions in the string library could help you.

But I believe a for loop would be a simple way of doing it as well.

local itemTypes = {
	"Something",
	"MostPowerful",
	"LeastPowerful",
	"Godly"
}

for _, v in ipairs(itemTypes) do 
	if script:FindFirstChild(v.."Item") then -- replace script with where you want to search from
		print("Found a special item!")
	elseif script:FindFirstChild("Item") then
		print("Found an item with no modifiers!")
	else
		print("No item was found!")
	end
end

image

"Found a special item! It was GodlyItem!"

image

"Found an item with no modifiers!"

image

"No item was found!" -- this is when an item was named incorrectly or doesn't exist
1 Like