How do i find a part with specific name if it is contained inside of an array?? I have tried to use table.find() and it gave me “nil” when there was a VehicleSeat inside of a cancollide false part
while true do
print("checking spawn1")
local alltouchedpartss = workspace:GetPartsInPart(Partt)
print(table.find(alltouchedpartss, "VehicleSeat"))
if table.find(alltouchedpartss, "VehicleSeat") then
print("yes")
end
task.wait(5)
end
You’ll have to use a loop to check. One way is create another table that changes the object to the name, such that you can then use table.find on it to find the index.
while true do
print("checking spawn1")
local alltouchedpartss = workspace:GetPartsInPart(Partt)
local alltouchedpartsss = {}
for _, part in ipairs(allthouchedpartss) do
table.insert(alltouchedpartsss, part.Name)
end
print(table.find(alltouchedpartsss, "VehicleSeat"))
if table.find(alltouchedpartsss, "VehicleSeat") then
print("yes")
end
task.wait(5)
end
Another method of doing it is to not use table.find at all, and instead just use a loop:
while true do
print("checking spawn1")
local alltouchedpartss = workspace:GetPartsInPart(Partt)
for index, part in ipairs(alltouchedpartss) do
if part.Name == "VehicleSeat" then -- or part:IsA("VehicleSeat")
print("yes")
break
end
end
task.wait(5)
end