Is a part's CanTouch property able to be set to false on touch?

Hey! So I’ve made a placement system for my tower defense game, but a problem that arises is that the projectiles shot from the towers prevent the towers from being placed. I attempted to resolve this, by making the part’s CanTouch property set to false which solved the problem with placing over the projectiles, however doing this causes the projectiles to not be interact-able with anything. I’m thinking that having the part’s CanTouch set to false when colliding with the towers will work out, but I am very new to scripting, and I’m not sure if this is possible.

How does your tower collision work? Maybe you could check if the thing that the tower is touching is a projectile, and ignore it if it is.

This is the script that inhabits the tower’s collisions:


-- Credit EgoMoose
local function checkHitbox(character, object)
	if object then
		local collided = false

		local collisionPoint = object.PrimaryPart.Touched:Connect(function() end)
		local collisionPoints = object.PrimaryPart:GetTouchingParts()

		for i = 1, #collisionPoints do
			if not collisionPoints[i]:IsDescendantOf(object) and not collisionPoints[i]:IsDescendantOf(character) then
				collided = true

				break
			end
		end

		collisionPoint:Disconnect()

		return collided
	end
end

local function checkBoundaries(plot, primary)
	local lowerXBound
	local upperXBound

	local lowerZBound
	local upperZBound

	local currentPos = primary.Position

	lowerXBound = plot.Position.X - (plot.Size.X*0.5) 
	upperXBound = plot.Position.X + (plot.Size.X*0.5)

	lowerZBound = plot.Position.Z - (plot.Size.Z*0.5)	
	upperZBound = plot.Position.Z + (plot.Size.Z*0.5)

	return currentPos.X > upperXBound or currentPos.X < lowerXBound or currentPos.Z > upperZBound or currentPos.Z < lowerZBound
end

local function ChangeTransparency(item, c)
	for i, o in next, item:GetDescendants() do
		if o then
			if o:IsA("Part") or o:IsA("UnionOperation") or o:IsA("MeshPart") then
				o.Transparency = c
			end
		end
	end
end

--Ignore above

local function place(plr, name, location, prefabs, cframe, c, plot)
	local item = prefabs:FindFirstChild(name):Clone()
	item.PrimaryPart.CanCollide = false
	item:SetPrimaryPartCFrame(cframe)

	ChangeTransparency(item, 1)

	if checkBoundaries(plot, item.PrimaryPart) then
		return
	end

	item.Parent = location

	if c then
		if not checkHitbox(plr.Character, item) then
			ChangeTransparency(item, 0)

			item.PrimaryPart.Transparency = 1

			return true
		else
			item:Destroy()

			return false
		end
	else
		ChangeTransparency(item, 0)

		item.PrimaryPart.Transparency = 1

		return true
	end
end

replicatedStorage.remotes.place.OnServerInvoke = place```

and the projectiles are in a CollisionGroup that damage only the player, and enemies. Anything specified, such as the barriers, destroy the projectile.

In your checkHitbox function, under the loop that checks whether something is colliding, add a check to see if the object is in the projectile collision group.