Region3 only detects 20 parts at max (datastore problem)

so, i was testing some datastore (since im new with it), and i was trying to save parts (making a dictionary so it doesn’t pop an error), but the thing is that im using region3 to detect all the parts that are placed on it, and when i check how many parts it saves, it always print 20 at max, idk if that is something about region3 or something, if someone can help me

part of the script that saves the parts:

cd.MouseClick:Connect(function(player)
	local pos1 = (plot.Position - 0.5*plot.Size)
	local pos2 = (plot.Position + (0.5*plot.Size)) + Vector3.new(0,50,0)
	local region = Region3.new(pos1,pos2)
	print(region.CFrame.Position)
	local parts = workspace:FindPartsInRegion3(region)
	local dataparts = {}
	local id = player.UserId
	for i,v in pairs(parts) do -- it is supposed to detect all parts in region3
		print(i) -- prints the index, 20 is always the last one
		dataparts[i] = {[1] = {v.Position.X,v.Position.Y,v.Position.Z},[2] = {v.Size.X,v.Size.Y,v.Size.Z}}
	end
	local ok, err = pcall(function()
		data:SetAsync(id,dataparts)
	end)
	if ok then
		print("saved")
	else
		error(err)
	end
end)

thanks for everyone who replies :smiley: (and sorry if there is any grammar mistake, im not english lol)

Region3 has it’s max parts limit set to 20 by default. You will need to include the maxParts parameter if you wanted to change this…

local parts = workspace:FindPartsInRegion3(region, nil, math.huge)

Also the second parameter is the ignoreList (nil above) which ignores the descendants of an instance.

Full Code
cd.MouseClick:Connect(function(player)
	local pos1 = (plot.Position - 0.5*plot.Size)
	local pos2 = (plot.Position + (0.5*plot.Size)) + Vector3.new(0,50,0)
	local region = Region3.new(pos1,pos2)
	print(region.CFrame.Position)
	local ignoreList = nil
	local parts = workspace:FindPartsInRegion3(region, ignoreList, math.huge)
	local dataparts = {}
	local id = player.UserId
	for i,v in pairs(parts) do -- it is supposed to detect all parts in region3
		print(i) -- prints the index, 20 is always the last one
		dataparts[i] = {[1] = {v.Position.X,v.Position.Y,v.Position.Z},[2] = {v.Size.X,v.Size.Y,v.Size.Z}}
	end
	local ok, err = pcall(function()
		data:SetAsync(id,dataparts)
	end)
	if ok then
		print("saved")
	else
		error(err)
	end
end)

Read more about FindPartsInRegion3: here

1 Like

thanks! i didn’t even know that it has a limit on it, i’ll try that out :smiley:

but otherwise, do you know if there is any method that is more effective, talking about part detecting? or is region3 the best option?

Spatial queries.