Hello,
I want to be able to find a player using workspace:GetPartBoundsInBox(), but I keep getting my function to return false instead of the desired true.
local function DetectParts(Character, Region3Part)
local PartsInRegion = workspace:GetPartBoundsInBox(Region3Part.CFrame, Region3Part.Size)
for _, Part in pairs(PartsInRegion) do
if Part.Parent:FindFirstChildOfClass("Humanoid") or Part.Parent.Name == Character.Name then
print("Character found in Region! *does dance*")
return true
else
return false
end
end
end
There could be a part that isn’t from the players character being returned in the “PartsInRegion” table. So in your loop it’s checking each part seeing if it can find a humanoid → doesn’t find it → returns false and stops the loop.
To fix just move your “return false” outside the loop. That way once all parts have been looped through, if I didn’t find the player then it will return false.