Voxel game has flickering chunks

so this is what’s happening:

and this is my localscript:

	local blocks = game.Workspace.Blocks
	local UnloadedChunks = game.ReplicatedStorage.UnloadedChunks
	local character = script.Parent
	local hrp = character:WaitForChild("HumanoidRootPart")
	local PlacementValidator = require(game.ReplicatedStorage.Modules.PlacementValidator)
	local ChunkRenderRadius = 5
	blocks.ChildAdded:Connect(function(child)
		if child:IsA("Folder") then
			-- You might want to comment out this line since it's not clear why you're calling this function here.
			-- PlacementValidator.CheckChunk(hrp.Position)
		end
	end)

	game.ReplicatedStorage.Events.ServerChunkAdded.OnClientEvent:Connect(function(value)
		--print("Chunk changed event triggered with value:", value)
		local playerChunkPos = PlacementValidator.CheckChunk(hrp.Position)

		
		local chunkPos = PlacementValidator.CheckChunk(hrp.Position)
		for _, v in pairs(blocks:GetChildren()) do
			local chunkName = v.Name -- Example chunk name
			local x, z = chunkName:match("Chunk_(-?%d+)_(-?%d+)")
			if x and z then
				x = tonumber(x)
				z = tonumber(z)
				
				local distanceX = math.abs(playerChunkPos.X - x)
				local distanceZ = math.abs(playerChunkPos.Z - z)

				local distance = distanceX + distanceZ
	
			if distanceX <= ChunkRenderRadius and distanceZ <= ChunkRenderRadius then
					--print("placed to storage")
				else
					v.Parent = UnloadedChunks
				end
			else
				print("Invalid chunk name format:", chunkName)
			end
		end
		
		for _, v in pairs(UnloadedChunks:GetChildren()) do
			local chunkName = v.Name -- Example chunk name
			local x, z = chunkName:match("Chunk_(-?%d+)_(-?%d+)")
			if x and z then
				x = tonumber(x)
				z = tonumber(z)
			local distanceX = math.abs(playerChunkPos.X - x)
			local distanceZ = math.abs(playerChunkPos.Z - z)

			local distance = distanceX + distanceZ
			if distanceX <= ChunkRenderRadius and distanceZ <= ChunkRenderRadius then

				local folder = v
				
				for i, v in pairs(folder:GetChildren()) do
					v.Parent = game.ReplicatedStorage.ChunksToLoad
				end
				folder.Parent = blocks
				for i, v in pairs(game.ReplicatedStorage.ChunksToLoad:GetChildren()) do
					if v:IsA("Part") then

						v.Parent = folder
						if v.Name == "Dirt" then
							--v:Destroy()
						end
						if math.fmod(i, 8) == 0 then
							task.wait()
						end
					end
				end
				
				--v.Parent = blocks
					--print("placed to workspace")
				task.wait()

			end
			else
				print("Invalid chunk name format:", chunkName)
			end
		end
	end)

why do chunks that should stay loaded unload and reload?
also, if i remove the task.wait (which is to not lag the game) the chunks flicker. still unloading then reloading.

if you need more context and scripts, let me know!