Here is something you can use. It doesn’t really make it simpler, it just means that if you add more names to the itemNames array, you don’t have to recode it
local itemNames = {
-- Put your names in here
}
local function onPickup(object, target)
local itemFound = nil
for index = 1, #itemNames do
if target[itemNames[index]] then
itemFound = target[itemNames[index]]
end
end
if itemFound then
local list = itemFound
...
end
Personally, I would use the script I just gave you because it means that if I change any values in the Array, I don’t have to re-program anything
If the target does not have an object with the specified name, it will error, FindFirstChild is required there
Also I dont know why you’re using a numerical for loop in this case when using pairs or ipairs is sufficient for the usecase
Think this would be a better way of doing what you had done
local itemNames = {
-- Put your names in here
}
local function onPickup(object, target)
local list
for _, name in ipairs(itemNames) do
list = target:FindFirstChild(name)
if not list then
continue
end
break
end
if list then
...
end