I am trying to find a Character using GetPartsInPart to teleport a player in a specific area.
The issue is that searching for HumanoidRootPart from the table returns nil.
while true do
task.wait(.5)
local a = workspace:GetPartsInPart(script.Parent)
print(table.find(a,"HumanoidRootPart"))
end
GetPartsInPart returns a table containing instances, and since you can’t use table.find in an Instance table with a string so you can find HumanoidRootPart with something like this:
local function FindRoot(t)
for i,v in pairs(t) do
if v.Name == "HumanoidRootPart" then
return v
end
end
return nil
end
while true do
task.wait(.5)
local a = workspace:GetPartsInPart(script.Parent)
print(FindRoot(a)) -- HumanoidRootPart if found, else nil
end