Detects the player's character in the area

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
1 Like

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

It works as per my requirements!
I did not know that table.find was not available.
Thanks for the advice!

1 Like

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