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
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
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.
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
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
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
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