Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Number of parts in region is 0?

Hello, I have a system that is supposed to prevent players from spawning multiple ships. A chunk of the code is pasted below. I have two parts, a min part and a max part. The position of the min part is (127, -11.75, 68) and the position of the max part is (-2, 79, 364.75). Whenever I print the amount of parts in the region, it outputs as 0 parts. How would I fix this?

local Obstruction = false
		
		-- do region 3 checker here
		local Obstruction = false
		local ObstructionRegion = Region3.new(location.ZoneMin.Position,location.ZoneMax.Position)
		local CheckForObstructions = workspace:FindPartsInRegion3WithIgnoreList(ObstructionRegion, location:GetChildren())
		print("Number of parts", #CheckForObstructions) -- outputs as 'Number of parts 0'
		for i,object in pairs(CheckForObstructions) do
			if object.Parent:FindFirstChild("SpawnPart") or object.Name == "PrimaryPartPlacement" then
				Obstruction = true
				break
			end
		end

In advance, thanks.

1 comment

0

location is a folder where the min/max parts are located

1 answer

✓ Accepted answer

Your region X size is negative, you need to make it positive, while 127 min, -2 max is negative, for example 127 min 128 max would make it one stud on X but it would be positive.

If you want easier way of making region you can just create new Part and create new region based off of the part's size, it is as easy as this:

local Part = Instance.new('Part')
Part.Anchored = true
Part.Size = Vector3.new(20, 20, 20)
Part.Parent = workspace

local Region = Region3.new(
	Part.Position - (0.5 * Part.Size),
	Part.Position + (0.5 * Part.Size)
)

I don't know math so i can't explain this "formula" if it even is but it's easy to remember.

You can also visualize a region by doing this:

local Region = Region3.new(...)

local Part = Instance.new('Part')
Part.Anchored = true
Part.Size = Region.Size
Part.CFrame = Region.CFrame
Part.Parent = workspace

That way you can be sure where the region is exactly.

This discussion is preserved as it was. New answers, comments, and votes are closed.