here is a version that uses workspace.Terrain:FillBlock
local distance = 16
local chunkSize = 16
local updateDistance = 128
local positionX = math.huge
local positionZ = math.huge
local heightData = {}
local loaded = {}
GetHeight = function(x, z)
if heightData[x] == nil then heightData[x] = {} end
if heightData[x][z] ~= nil then return heightData[x][z] end
local height = 0
height += math.noise(x * 0.01, 0, z * 0.01) * 40
height += math.noise(x * 0.04, 0, z * 0.04) * 10
heightData[x][z] = height
return height
end
Load = function(x, z)
local minimum = math.huge
local maximum = -math.huge
for xx = x-1, x+1 do
for zz = z-1, z+1 do
local height = GetHeight(xx, zz)
minimum = math.min(minimum, height)
maximum = math.max(maximum, height)
end
end
local slope = maximum - minimum
local height = heightData[x][z]
local thickness = height - minimum + 6
local position = Vector3.new(x * 4, height, z * 4)
local cFrame = CFrame.new(x * 4 + 2, height - thickness / 2, z * 4 + 2)
local size = Vector3.new(4, thickness, 4)
if slope < 1 then
workspace.Terrain:FillBlock(cFrame, size, Enum.Material.Mud)
else
workspace.Terrain:FillBlock(cFrame, size, Enum.Material.Sand)
end
if height >= 0 then return end
thickness = -height
local cFrame = CFrame.new(x * 4 + 2, height + thickness / 2, z * 4 + 2)
local size = Vector3.new(4, thickness, 4)
workspace.Terrain:FillBlock(cFrame, size, Enum.Material.Water)
end
LoadChunk = function(chunkX, chunkZ)
if loaded[chunkX] == nil then loaded[chunkX] = {} end
if loaded[chunkX][chunkZ] ~= nil then return end
loaded[chunkX][chunkZ] = true
local startX = chunkX * chunkSize
local startZ = chunkZ * chunkSize
local endX = startX + chunkSize - 1
local endZ = startZ + chunkSize - 1
for x = startX, endX do
for z = startZ, endZ do
Load(x, z)
end
end
wait()
end
LoadChunks = function(chunkX, chunkZ)
local x, z = chunkX, chunkZ
local dx, dz = 1, 0
local passed, length = 0, 1
LoadChunk(x, z)
for i = 1, (distance * 2 + 1) * (distance * 2 + 1) - 1 do
x += dx z += dz
if Vector2.new(chunkX - x, chunkZ - z).Magnitude < distance + 0.5 then LoadChunk(x, z) end
passed += 1
if passed == length then passed = 0 dx, dz = -dz, dx if dz == 0 then length += 1 end end
end
end
workspace.CurrentCamera:GetPropertyChangedSignal("Focus"):Connect(function()
local x = workspace.CurrentCamera.Focus.Position.X
local z = workspace.CurrentCamera.Focus.Position.Z
if Vector2.new(positionX - x, positionZ - z).Magnitude < updateDistance then return end
positionX, positionZ = x, z
LoadChunks(math.floor(x / 4 / chunkSize), math.floor(z / 4 / chunkSize))
end)