Finding a certain value in an array with an unknown order

I am using :GetTouchingParts(), and I am trying to check to see if a ball is still touching a brick every .1 seconds.

There is more than one part touching the brick. I am assigning the ball a variable earlier in the script. How do I find the ball in the array?

This reply to your previous post about this is still valid. It is the most efficient way to check if an array contains a certain part.

When you say you are assigning the ball a variable, do you mean that you are doing something like:

local Ball = workspace.Ball

Then you can try this:

function Main()
    while wait(0.1) do
        local IsTouching = CheckParts(DesiredBrick)
        If IsTouching then
            print(“Not touching”)

function CheckParts(DesiredBrick)
    local Found = false
    local TouchingParts = DesiredBrick:GetTouchingParts()
    for I, v in pairs(TouchingParts) do
        If v == Ball then
            Found = true
    return Found

Sorry, I just had a few problems with it. But after looking back over the code, I actually understand how it works now.

I just found out why this wasn’t working. :GetTouchingParts only creates an array of intersecting parts. It should really be named :GetIntersectingParts .