Minecraft Chunk Loading isn't working

  1. What do you want to achieve? Keep it simple and clear!
  • I’ve made a Producerally/Voxel Generation just like in Minecraft, but due to the Textures, the game is laggy even when the world is 64x64.
  1. What is the issue? Include screenshots / videos if possible!
  • I don’t have any screenshots or videos but yeah i hope you understood.
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
  • Yeah, nothing helped.

So far, i’ve tried this code i made, but it doesn’t work. At one point it even stops loading the chunks.

local CurrentCamera = workspace.CurrentCamera
local Rendered = workspace.Rendered
local Chunks = game.ReplicatedStorage.Chunks

local Table = {}

while wait() do
	for i, v in pairs(Rendered:GetChildren()) do
		if v:IsA("BasePart") then
			local GetDistance = (CurrentCamera.CFrame.Position - v.Position).Magnitude
			
			if GetDistance > 32 then
				v.Parent = Chunks
				table.insert(Table, v)
			elseif GetDistance < 32 then
				for a, b in pairs(Table) do
					b.Parent = workspace
				end
				
				table.remove(Table, GetDistance)
			end
		end
	end
end

I need help with this, please.
And no, i don’t wanna work with StreamingEnabled because it doesn’t unload the chunks from behind the player.

2 Likes

it’d definetly help if there was a video or a bit more information;

right now im assuming that the script you’ve shown it is a localscript; as loading chunks should only be handled on the client.

what im thinking may be the problem is that either the script isnt or stops running; or that theres a problem with using current camera.

i’d use print statements to see if theres a problem with the code, mabye instead of getting the cameras cframe you should get the humanoidrootparts cframe instead.

1 Like

Tehnically, the script is working but when i try running it, the whole map dissapears. It unloads everything instead of loading blocks that are 32 studs near the player.

1 Like

i would recommend looking at your calculation for the distance; for one you arent unloading everything by the distance of the character, you are unloading everything by the distance of the camera.

another thing is that i believe position relates to the middle of the object, so if your chunk/floor has a large y size the code will think its farther away then it actually is.

i would try printing the GetDistance variable to see if you are actually counting by studs; because if im correct studs arent caluclated via magnitude.

you also have a if else statement for when getdistance is bigger then or smaller then 32, but nothing for when the variable is equal to 32.

Yeah nevermind, i’ve figured it out by using StreamEnabled and made a script that checks if the player is 20 studs near a part and if it is set that part to transparency 0 if he’s 20 studs far away set that to transparency 1.

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