Collision detection placement script help

I have a very simple placement script and so far the objects can collide with parts. I need help preventing that.

LocalScipt
local BuildingCF = CFrame.new()
local PlaceObject = game.ReplicatedStorage.Events.PlaceBuilding
local mouse = game.Players.LocalPlayer:GetMouse()
local FakeBuilding = game.ReplicatedStorage.Spawnables.Buildings.FakeBuilding

mouse.TargetFilter = FakeBuilding

local Snap = 1

local shouldBeFiring = true


for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("ImageButton") then
	
	local button = v
	
	v.MouseButton1Click:Connect(function()
		shouldBeFiring = true
		
		FakeBuilding.Parent = workspace
	
		
		if shouldBeFiring == true then
			mouse.Move:Connect(function()
				BuildingCF = CFrame.new(
					math.floor(mouse.Hit.X / Snap + 0.5) * Snap,
					1,
					math.floor(mouse.Hit.Z / Snap + 0.5) * Snap
				)
					
				FakeBuilding:SetPrimaryPartCFrame(BuildingCF)
				
				
				
			end)
		end




		
		
		
		mouse.Button1Down:Connect(function()
			if shouldBeFiring == true then
				PlaceObject:FireServer(BuildingCF, button)
				shouldBeFiring = false
			end
			if shouldBeFiring == false then
				FakeBuilding.Parent = game.ReplicatedStorage
			end
		end)
	end)
	end
end
Script
local PlaceObject = game.ReplicatedStorage.Events.PlaceBuilding

PlaceObject.OnServerEvent:Connect(function(player, BuildingCF, button)
    local building = game.ReplicatedStorage.Spawnables.Buildings[button.Name]:Clone()
    building:SetPrimaryPartCFrame(BuildingCF)
    building.Parent = workspace
    building.Main.BrickColor = player.TeamColor
end)
1 Like

I suggest using regions for this, you could create a new region and check for any interceptions every time the object is moved. You would also need to do the check when your about to place the object. You need to reconsider this approach if it’s possible that something appears and creates a collision. In such a case you would need to do constant checks.

2 Likes

You could use GetTouchingParts() to check if anything is colliding with the object. Make sure to check if the colliding object isn’t a part of what you are placing, and that it is a part of a prop.
You can also use CollisionGroups to make the item being placed have no collision for players, but still can be touched by other parts.
Keep in mind that it has to be CanCollide true to check if anything is touching.

2 Likes

Thank you, i appreciate the correct response.

What happened with my response? Wasn’t it correct? ;(

This always happens to me ;(

1 Like

yes, region3 works out just the same way.