Simple made Chunk System

local Allparts = {}
local OldParents = {}
local Player = game:GetService('Players').LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local con,con2
local ChunkSize = 200
local lp
local Humanoid = Character:WaitForChild('Humanoid')
for i,v in ipairs(workspace.Map.Builds:GetDescendants()) do
	if (v:IsA('BasePart')) then
		table.insert(Allparts,v)
		OldParents[v] = v.Parent
	end
end

con2 = Humanoid.Died:Connect(function()
	if (con) then
		con:Disconnect()
	end
	if (con2) then
		con2:Disconnect()
	end
end)

con = Humanoid:GetPropertyChangedSignal('MoveDirection'):Connect(function()
	for i,v in ipairs(Allparts) do
		if (Player:DistanceFromCharacter(v.Position) > ChunkSize) then
			if (lp ~= v) then
				v.Parent = nil
				lp = v
				end
		else
			v.Parent = OldParents[v]
			
			end
	end
end)

I just made this simple chunk loading!
I want your thougs!
It’s simple, but, I think it’s efficient, what do you think?

5 Likes

Hi!

I think table.insert could be optimized further with table[#table + 1] = v
You probably knew this already, but a # in front of a table returns its length :slight_smile: