GetPartBoundsInBox detecting parts outside of box

please forgive my un optimized script and this post first time posting
You can write your topic however you want, but you need to answer these questions:

  1. What do i want to achieve?
    What i want to happens is for my selection box (Red transparent box) to detect parts within the bounding box and put a point where i can spawn a fire at, this point is a part

  2. What is the issue?
    parts like these trees often detect each other even if they are not inside the bounding box of the other tree, causing it to leave a point on a completely different tree


    robloxapp-20241217-1518265.wmv (395.7 KB)

  3. What solutions have i tried so far?
    Go crazy & read documentation

This is the code, for reference gets 25% of points from each object, each tree only can detect 2 points, 25% of 2 points is 0.5 therefore none of those trees should have a point, but they do. you can also visually see this by watching each point generate and seeing a random point off into a different object model

Ive tried spacing them out far and wide, no avail

Here is part of the code

	local BoundingBoxKlone -- Placeholder
	
	if Object:IsA("Model") then
		local Orientation, Size = Object:GetBoundingBox()
		local PinBound = workspace:GetPartBoundsInBox(Orientation,(Size - Vector3.new(0.1,0.1,0.1)))
		local Points = {}
		local SelectedPoints = {}
		
		if Debug == true then
			BoundingBoxKlone = BoundingBox:Clone()
			BoundingBoxKlone.Parent = workspace
			BoundingBoxKlone.CFrame = Orientation
			BoundingBoxKlone.Size = Size
		end
		
		wait(1.5)
		
		
		for _,v:Part in pairs(PinBound) do
			print(v.Name)
			local point = Instance.new("Part")
			point.Anchored = true
			point.Size = Vector3.new(0.1,0.1,0.1)
			point.Position = v.Position
			point.Parent = PointsFolder
			table.insert(Points,point)
			if Debug == true then
				local spher = sphere:Clone()
				spher.Parent = point
				sphere.Adornee = v	
			end
			wait()
		end
		
		BoundingBoxKlone:Destroy()
		
		wait(1.5)
		
		local ammount = math.floor((#Points * Percent) / 100)
		for count = 0,ammount,1 do
			local Sindex = math.random(0,#Points)
			local Spoint = Points[Sindex]
			table.remove(Points,Sindex)
			table.insert(SelectedPoints,Spoint)
		end
		
		for _,v in pairs(Points) do
			if table.find(SelectedPoints,v) == nil then
				v:Destroy()
			end
		end
	end

Here’s a low quality video on the point generation in action
robloxapp-20241217-1520323.wmv (552.1 KB)

I FOUND THE PROBLEM, I AM THE PROBLEM
image

1 Like