Check if 2 parts intersect

I’m trying to make a tower defense game, and I’m thinking of how to do the tower placement system. I want the player to be able to place a tower within a region 3, and only if the tower is touching a part that belongs to a folder (ie. “Valid Areas”). I also want it so that they can’t place a part if it is touching a part in a “props” folder. And of course, I want the check to be server sided. (the client checks first so that non-exploiters wouldn’t have an issue, but ultimately server sided)
This is the best way I can think of for how to make it so that the towers don’t intersect with the props, without doing a lot of technical things. If there’s a better way, I’m open to hearing it, but my question is, how can I check on the server if a part is already colliding with another part, and/or crossing another part already, for the purposes stated above?

1 Like
local function GetTouchingParts(part)
   local connection = part.Touched:Connect(function() end)
   local results = part:GetTouchingParts()
   connection:Disconnect()
   return results
end

local results = GetTouchingParts(workspace.PartA)
print(#results)
-- (GetTouchingParts) Returns a table

[Tables | Roblox Creator Documentation]

I tried this but it didn’t work. It errored “GetTouchingParts is not a valid member of part “workspace.Test” (my test part)” Also, how would this help me check if a part is colliding with another?

local function checkIfColliding(part, targetparts)
      for i, targetpart in pairs(targetparts) do
            local p1 = targetpart.Position - (targetpart.Position/2)
            local p2 = targetpart.Position + (targetpart.Position/2)
            local reg = Region3.new(p1, p2)
            local partsinregion = workspace:FindpartsInRegion3(reg, nil, 1000)
            for a, partsinsideregion in pairs(partsinregion) do
                  if partsinsideregion  == part then
                         return true
                  end
            end
      end
      return false
end
local partstocheckcolliding = validareas:GetChildren()
local defensetower = --define this as the tower

if checkIfColliding(defensetower, partstocheckcolliding) == true then
print("yes yes place ur tower")
else
print("no thats a bad place dont place there")
end

try this

I suggest using ZonePlus. I used it and stuff are going nice.