Trouble with "GetPartBoundsInBox" for map generation script

I’m trying to troubleshoot a script that was causing lag and only ended up causing more problems. I’m generating infinite tiles around the player and deleting the old ones behind them, but it was causing lag so I’m using “GetPartBoundsInBox” to see what tiles are already generated so I don’t delete and rebuild them.

Unfortunately, I have had many many different issues working with this script and so I’ve given up and I’m posting it here. The problem right now is that not only is the function returning parts that very clearly are not in the “Root” collision group, nothing after the line “print(AlreadyGeneratedChunks)” prints at all, despite the tiles still generating.

I haven’t tried any solutions because I literally can’t debug this script if nothing after aforementioned line is going to print.

Here is my script, hopefully it’s readable:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Folder = ReplicatedStorage.Map.Floor
local player = game:GetService("Players").LocalPlayer
player.CharacterAdded:Wait()
local HumanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")

local CurrentChunk
local Floor1 = Folder:WaitForChild("TileFloor")
local Floor2 = Folder:WaitForChild("TileFloor2")
local GeneratedTile

local Params = OverlapParams.new()
Params.FilterDescendantsInstances = workspace.Map.CheckerFloor:GetDescendants()
Params.FilterType = Enum.RaycastFilterType.Include
Params.CollisionGroup = "Root"

local AGCPositions = {} -- Stands for "Already Generated Chunk Positions". Normally I'm way against using acronyms but this code is already bulky enough

local Debounce = false

local function generateChunk(centerPosition)
	local chunk = {}
	table.clear(chunk)
	for x = -2, 2 do
		for z = -2, 2 do
			local position = Vector3.new(x, 0, z)
			table.insert(chunk, position)
		end
	end
	return chunk
end

HumanoidRootPart.Touched:Connect(function(hit)
	if hit.Name == "LoadConnected" and hit.ClassName == "Part" then
		if hit ~= CurrentChunk and Debounce == false then
			CurrentChunk = hit
			
			if hit.Parent.Name == "TileFloor" then
				Floor1 = Folder.TileFloor
				Floor2 = Folder.TileFloor2
			else
				Floor1 = Folder.TileFloor2
				Floor2 = Folder.TileFloor
			end
			
			table.clear(AGCPositions)
			
			local AlreadyGeneratedChunks = workspace:GetPartBoundsInBox(CFrame.new(hit.Position), Vector3.new(360, 50, 360), Params)
			print(AlreadyGeneratedChunks)
			print("13") -- HELP ME I'M GONNA LOSE MY ################!!!!
			for i, v in ipairs(AlreadyGeneratedChunks) do
				table.insert(AGCPositions, v.Position)
				print("12")
			end
			print("11")
			for i, v in ipairs(generateChunk(hit.Parent.Root.Position)) do
				print("10")
				if v ~= Vector3.new(0, 0, 0) then
					print("9")
					if math.abs(v.X) == math.abs(v.Z) or math.abs(v.X) + math.abs(v.Z) == 2 then
						GeneratedTile = Floor1:Clone()
						print("8")
					else
						GeneratedTile = Floor2:Clone()
						print("7")
					end					
					print("6")
					GeneratedTile.Parent = workspace.Map.CheckerFloor
					print("5")
					GeneratedTile.Root.CFrame = CFrame.new(hit.Parent:FindFirstChild("Root").Position.X + (72 * v.X), .5, hit.Parent:FindFirstChild("Root").Position.Z + (72 * v.Z))
					print("4")
					GeneratedTile:SetAttribute("New", true)
					print("3")
				end
				print("2")
			end
			print(AGCPositions)
			print("1")
			for i, v in pairs(workspace.Map.CheckerFloor:GetDescendants()) do
				if v.Name == "Root" then
					if v:GetAttribute("New") == false and v.Parent ~= hit.Parent then
						v.Parent:Destroy()
					else
						v:SetAttribute("New", false)
					end
				end
			end
		end
	end
end)

I hope I didn’t sound too annoyed in this post. I hope one can understand why I might be a bit aggravated after working on this for like 3 days :frowning:

It fixed itself… IDK why it didn’t work in the first place probably broken and Roblox released a patch or smth maybe my computer was on fire and I didn’t notice IDK

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.