Need Help with my code

I want to make it work as if the object I am trying to place intersects any parts that is inside the “WhitelistedToPlace” folder it will return true.

its not working for me hope someone can help me :pray:

function PlacementValidator.NotIntersectingObjects(objectSize, worldCF)
	-- Check if worldCF is valid (not nil)
	if not worldCF then
		warn("Received nil CFrame in NotIntersectingObjects")
		return false  -- Return false to indicate failure in intersection check
	end

	-- Get all the parts that the object would intersect with in the specified area
	local parts = workspace:GetPartBoundsInBox(worldCF, objectSize)

	-- Check for intersection with parts inside the "WhitelistedToPlace" folder
	local whitelistedFolder = workspace:FindFirstChild("WhitelistedToPlace")
	if not whitelistedFolder then
		warn("WhitelistedToPlace folder not found!")
		return false  -- No whitelisted parts, so return false
	end

	-- Flag to track if the intersection is with a whitelisted part
	local canPlaceOnWhitelist = false

	-- Check for intersections
	for _, part in ipairs(parts) do
		-- If the part is a descendant of the "WhitelistedToPlace" folder, it's a valid intersection
		if whitelistedFolder:IsDescendantOf(part) then
			canPlaceOnWhitelist = true
		else
			-- If part is not in the whitelist, do not allow placement
			return false
		end
	end

	-- Allow placement only if intersection is with whitelisted parts
	if canPlaceOnWhitelist then
		return true
	end

	-- Otherwise, return false
	return false
end

Video Showing my problem:
https://streamable.com/gp27gl

its because the part isnt intersecting with the white pad, its just sitting on top. instead, you could check if the players mouse target is a valid part to place stuff on, iunstead of using spacial query like this.

can you please tell me how can I do it?

i don’t understand that

i think here u meant:

if part:IsDescendantOf(whitelistedFolder) then

I have tried right now still have not changed anything

Can you show the updated code?

function PlacementValidator.NotIntersectingObjects(objectSize, worldCF)
	-- Check if worldCF is valid (not nil)
	if not worldCF then
		warn("Received nil CFrame in NotIntersectingObjects")
		return false  -- Return false to indicate failure in intersection check
	end

	-- Get all the parts that the object would intersect with in the specified area
	local parts = workspace:GetPartBoundsInBox(worldCF, objectSize)

	-- Check for intersection with parts inside the "WhitelistedToPlace" folder
	local whitelistedFolder = workspace:FindFirstChild("WhitelistedToPlace")
	if not whitelistedFolder then
		warn("WhitelistedToPlace folder not found!")
		return false  -- No whitelisted parts, so return false
	end

	-- Flag to track if the intersection is with a whitelisted part
	local canPlaceOnWhitelist = false

	-- Check for intersections
	for _, part in ipairs(parts) do
		-- If the part is a descendant of the "WhitelistedToPlace" folder, it's a valid intersection
		if part:IsDescendantOf(whitelistedFolder) then
			canPlaceOnWhitelist = true
			print(canPlaceOnWhitelist)
		else
			-- If part is not in the whitelist, do not allow placement
			return false
		end
	end

	-- Allow placement only if intersection is with whitelisted parts
	if canPlaceOnWhitelist then
		return true
	end

	-- Otherwise, return false
	return false
end

image

the problem is here

	if not success then
		return false
	end

if its true then it needs to skip it to next part of the code I am wrong?

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TryPlace = ReplicatedStorage.TryPlace
local placeableObjects = ReplicatedStorage.PlaceableObjects
local PlacementValidator = require(ReplicatedStorage.PlacementValidator)

function Place(player, name, targetCF)

	local object = placeableObjects:FindFirstChild(name)
	if not object then
		return false
	end

	local objectSize = object:GetExtentsSize()

	-- Check if placement is within bounds
	if not PlacementValidator.WithinBounds(objectSize, targetCF) then
		return false
	end

	-- Check for intersection with other objects
	local success = PlacementValidator.NotIntersectingObjects(objectSize, targetCF)
	if not success then
		return false
	end
	
	-- Proceed with cloning and placing the object
	local newObject = object:Clone()
	newObject:PivotTo(targetCF)
	newObject.Parent = game.Workspace.PlacedProducts

	return true
end

Well can you try this instead:

if part:IsDescendantOf(whitelistedFolder) then
			canPlaceOnWhitelist = true
			print(canPlaceOnWhitelist)
			return canPlaceOnWhitelist or true
		else
			-- If part is not in the whitelist, do not allow placement
			return false
		end

updated code:

function PlacementValidator.NotIntersectingObjects(objectSize, worldCF)
	-- Check if worldCF is valid (not nil)
	if not worldCF then
		warn("Received nil CFrame in NotIntersectingObjects")
		return false  -- Return false to indicate failure in intersection check
	end

	-- Get all the parts that the object would intersect with in the specified area
	local parts = workspace:GetPartBoundsInBox(worldCF, objectSize)

	-- Check for intersection with parts inside the "WhitelistedToPlace" folder
	local whitelistedFolder = workspace:FindFirstChild("WhitelistedToPlace")
	if not whitelistedFolder then
		warn("WhitelistedToPlace folder not found!")
		return false  -- No whitelisted parts, so return false
	end

	-- Flag to track if we find any non-whitelisted parts
	local canPlaceOnWhitelist = false

	-- Check for intersections
	for _, part in ipairs(parts) do
		
		if part:IsDescendantOf(whitelistedFolder) then
			canPlaceOnWhitelist = true
			print(canPlaceOnWhitelist)
			return canPlaceOnWhitelist or true
		else
			-- If part is not in the whitelist, do not allow placement
			return false
		end
	end
end

function Place(player, name, targetCF)

	local object = placeableObjects:FindFirstChild(name)
	if not object then
		return false
	end

	local objectSize = object:GetExtentsSize()

	-- Check if placement is within bounds
	if not PlacementValidator.WithinBounds(objectSize, targetCF) then
		return false
	end
	
	-- Check for intersection with other objects
	local success = PlacementValidator.NotIntersectingObjects(objectSize, targetCF)
	if not success then
		return false
	end
	print(success)
	
	-- Proceed with cloning and placing the object
	local newObject = object:Clone()
	newObject:PivotTo(targetCF)
	newObject.Parent = game.Workspace.PlacedProducts

	return true
end

not printing or doing anything