Ok, so I'm making a procedural terrain generator based off of Roblox's example. However, it only generates 4 chunks, then stops. No errors. The idea is that it will scan around the player in a certain proximity, get all of the points on a 64-voxel grid inside of that proximity, and then generate new chunks using those points as a starting location. I've removed some code that I've singled out as not the problem, and some that is irrelevant to the situation.
local CHUNK_MAX_HEIGHT = 0
local CHUNK_SIZE = 64
local RENDER_DISTANCE = 120 / 4
local chunks = {}
local function chunkExists(chunkX, chunkZ)
if not chunks[chunkX] then
chunks[chunkX] = {}
end
return chunks[chunkX][chunkZ]
end
local function Round(to_round)
local divided = to_round / CHUNK_SIZE
local rounded = CHUNK_SIZE * math.floor(divided)
return rounded
end
function checkSurroundings(location)
local chunkX, chunkY, chunkZ = Round(math.floor(location.X / 4)), CHUNK_MAX_HEIGHT, Round(math.floor(location.Z / 4))
local range = math.max(1, RENDER_DISTANCE / CHUNK_SIZE)
for x = -range, range do
for z = -range, range do
print(chunkX, chunkZ)
local cx = chunkX + x
local cy = CHUNK_MAX_HEIGHT
local cz = chunkZ + z
if not chunkExists(cx, cz) then
local chance = math.random(1, BIOME_CHANGE_CHANCE)
if chance == BIOME_CHANGE_CHANCE then
BIOME = BIOMES[math.random(1, #BIOMES)]
end
print(cx, cy, cz)
makeChunk(cx, cy, cz)
end
end
end
end
while true do
for _, player in pairs(Players:GetPlayers()) do
if player.Character then
local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
checkSurroundings(humanoidRootPart.Position)
end
end
end
wait(1)
end
I have no idea why it isn't working, help?
EDIT On further inspection, it seems to stop at -64 as the X and Z coordinate.
