I’m trying to make what the title says but i get the error Unable to cast region3int16 to bool error on line 37, what am i doing wrong
local islandSize = 512 -- The size of the island, in studs
local mountainHeight = 100 -- The height of the mountain, in studs
local beachHeight = 10 -- The height of the beach, in studs
local oceanDepth = 30 -- The depth of the ocean, in studs
-- Get the existing terrain object and clear it
local terrain = game:GetService("Workspace").Terrain
terrain:Clear()
-- Generate a base terrain using Perlin noise
local baseTerrain = {}
for i = 0, islandSize do
baseTerrain[i] = {}
for j = 0, islandSize do
-- Generate a random height using 2D Perlin noise
local height = math.noise(i/100, j/100, 0) * 50 + 50
baseTerrain[i][j] = height
end
end
-- Add a mountain in the center of the island
local centerX, centerY = islandSize/2, islandSize/2
for i = 0, islandSize do
for j = 0, islandSize do
-- Calculate the distance from the center of the island
local dx, dy = i - centerX, j - centerY
local distance = math.sqrt(dx*dx + dy*dy)
-- Add height to the terrain within a certain radius of the center
if distance < islandSize/4 then
baseTerrain[i][j] = baseTerrain[i][j] + math.max(mountainHeight - distance*2, 0)
end
end
end
-- Apply the base terrain to the terrain object
terrain:PasteRegion(baseTerrain, Region3int16.new(Vector3int16.new(0, 0, 0)), Vector3int16.new(islandSize, 200, islandSize), true, Enum.Material.Grass)
-- Smooth the terrain to remove sharp edges
terrain:Smooth()
-- Flatten the terrain around the mountain peak to create a plateau
local peakHeight = baseTerrain[centerX][centerY] + mountainHeight
terrain:FillBall(Vector3.new(centerX, peakHeight, centerY), islandSize/8, Enum.Material.Rock, true)
-- Flatten the terrain around the base of the mountain to create a beach
terrain:FillBall(Vector3.new(centerX, 0, centerY), islandSize/2, Enum.Material.Sand, true)
-- Create an ocean around the island
local oceanSize = islandSize + 100
local oceanTerrain = {}
for i = 0, oceanSize do
oceanTerrain[i] = {}
for j = 0, oceanSize do
-- Generate a depth using 2D Perlin noise
local depth = math.noise(i/300, j/300, 0) * 20 + oceanDepth
oceanTerrain[i][j] = depth
end
end
terrain:PasteRegion(oceanTerrain, Region3int16.new(Vector3int16.new(-(oceanSize/2), 0, -(oceanSize/2))), Vector3int16.new(oceanSize, oceanDepth, oceanSize), true, Enum.Material.Water)
-- Smooth the ocean terrain to create a more natural look
terrain:Smooth()
-- Flatten the terrain around the edge of the ocean to create a beach
terrain:FillRegion(Region3.new(Vector3.new(-(oceanSize/2), 0, -(oceanSize/2)), Vector3.new(oceanSize/2, 0, oceanSize/2)), Enum.Material.Sand, true)
print("Island generated successfully!")