Placement system having false positive collisions

Hey! I’m having some issues with my placement system that I’m really not sure of any way of fixing. Whenever you join in-game you can place any tiles next to each other. But the thing is after you rejoin and you try placing it adjacent to the other tile, it’ll “fail”, here’s an example video WITH the output open displaying “colliding” parts: Video

PLEASE, any suggestions are amazing. Here’s my collision script:

local function CheckForTouching(Model)
	local isColliding = false
	local objectTouched
	
	local Touch = Model.PrimaryPart.Touched:Connect(function() end)
	local Touching = Model.PrimaryPart:GetTouchingParts()

	for i = 1, #Touching do
		if (not Touching[i]:IsDescendantOf(Model)) then
			isColliding = true
			objectTouched = Touching[i].Name
		end
		
		if Touching[i] == workspace.Terrain then
			isColliding = false
			objectTouched = nil
		end
		if Touching[i].Name == "Border" then
			isColliding = false
			objectTouched = nil
		end
		if Touching[i].Name == "Corner" then
			isColliding = false
			objectTouched = nil
		end
		if Touching[i].Name == "MainPlant" then
			isColliding = false
			objectTouched = nil
		end
		if Touching[i].Name == "WaterRadius" then
			isColliding = false
			objectTouched = nil
		end
	end

	local Magnitude = (LocalPlayer.Character.HumanoidRootPart.Position - Model.PrimaryPart.Position).Magnitude
	if Magnitude > 25 then
		isColliding = true
		objectTouched = "Magnitude"
	end
	if GetTiles() >= ShovelValue then
		isColliding = true
		objectTouched = "ShovelValue"
	end
	
	if objectTouched ~= nil then
		print(objectTouched)
	end
	
	Touch:Disconnect()
	return isColliding
end

I’m going to make a guess, and it could be wrong: In your loop [for i = 1, #Touching do], you are not breaking your loop if a part is found to be touching (the first if condition in the loop). I feel like the loop should probably break if it finds a part that it considers to be touching. Otherwise, another part might pass the condition and then mark it as not colliding. So try adding a break within that first if condition in the loop (after the objectTouched = Touching[i].Name line).

If that doesn’t work, we might need more info on how your placement system and save/load system is working, to check if it just happens to be small floating-point precision errors or something.

1 Like

A few things real quick:

  1. I solved this a few hours ago (sorry for not closing the post), it ended up being that whenever am object was loaded onto the plot the object would SLIGHTLY offset (0.001). So I ended up fixing that, as well as implementing a better way of looping thru the objects, like you suggested.

  2. A tip for any other people that might be experiencing this problem, you may need to round the position of any loaded objects from a placement system. I was saving CFrames directly into my data system, with CFrame.new(unpack(cf)). Turns out, it’s a little inaccurate and can cause some random issues.

  3. Thirdly, it’s my honor to be replied to by the sleitnick. I’m a massive fan, and love your work. Good luck with your future, and thanks for the help!

1 Like

Glad you figured it out! I have faced a lot of similar issues in the past with build systems. It’s very gratifying to get them working.

1 Like