Roblox Ocean & Island Generation Script
Here's a script that will generate a large ocean with sand at the bottom, a cave system, and small islands. This script should be placed in a Script object in ServerScriptService.
-- Ocean & Island Generation Script for Roblox
local Terrain = workspace.Terrain
local WORLD_SIZE = 2048 -- Size of the world in studs
local WATER_HEIGHT = 100 -- Height of the water level
local SAND_DEPTH = 20 -- Depth of the sand layer
local CAVE_DEPTH = 50 -- Depth where caves start forming
local ISLAND_COUNT = 15 -- Number of small islands to generate
-- Clear existing terrain (optional)
Terrain:Clear()
-- Generate flat ocean floor with sand
Terrain:FillBlock(CFrame.new(0, -SAND_DEPTH, 0), Vector3.new(WORLD_SIZE, SAND_DEPTH, WORLD_SIZE), Enum.Material.Sand)
-- Generate water
Terrain:FillBlock(CFrame.new(0, WATER_HEIGHT/2, 0), Vector3.new(WORLD_SIZE, WATER_HEIGHT, WORLD_SIZE), Enum.Material.Water)
-- Function to generate caves
local function generateCaves()
local caveCount = math.random(10, 20)
for i = 1, caveCount do
local caveX = math.random(-WORLD_SIZE/2 + 100, WORLD_SIZE/2 - 100)
local caveZ = math.random(-WORLD_SIZE/2 + 100, WORLD_SIZE/2 - 100)
local caveY = -math.random(CAVE_DEPTH, CAVE_DEPTH + 30)
-- Main cave tunnel
local caveLength = math.random(50, 150)
local caveWidth = math.random(10, 20)
local caveHeight = math.random(8, 15)
-- Create a winding cave
for segment = 1, 5 do
local segmentLength = caveLength / 5
local direction = math.random() * math.pi * 2
local endX = caveX + math.cos(direction) * segmentLength
local endZ = caveZ + math.sin(direction) * segmentLength
-- Dig out the cave segment
Terrain:FillBlock(
CFrame.new((caveX + endX)/2, caveY, (caveZ + endZ)/2),
Vector3.new(caveWidth, caveHeight, segmentLength),
Enum.Material.Air
)
-- Add some variation to the cave shape
for variation = 1, 3 do
local varX = math.random(-caveWidth/2, caveWidth/2)
local varZ = math.random(-segmentLength/2, segmentLength/2)
local varY = math.random(-caveHeight/2, caveHeight/2)
Terrain:FillBall(
CFrame.new(caveX + varX, caveY + varY, caveZ + varZ),
math.random(3, 8),
Enum.Material.Air
)
end
caveX, caveZ = endX, endZ
end
end
end
-- Function to generate small islands
local function generateIslands()
for i = 1, ISLAND_COUNT do
local islandX = math.random(-WORLD_SIZE/2 + 100, WORLD_SIZE/2 - 100)
local islandZ = math.random(-WORLD_SIZE/2 + 100, WORLD_SIZE/2 - 100)
local islandSize = math.random(20, 50) -- Small islands
-- Base of the island (sand)
Terrain:FillBlock(
CFrame.new(islandX, -SAND_DEPTH + 5, islandZ),
Vector3.new(islandSize, 10, islandSize),
Enum.Material.Sand
)
-- Island terrain (grass)
local height = math.random(5, 15)
Terrain:FillBall(
CFrame.new(islandX, -SAND_DEPTH + 5 + height/2, islandZ),
Vector3.new(islandSize/2, height, islandSize/2),
Enum.Material.Grass
)
-- Add some rocks to the island
for rock = 1, math.random(3, 8) do
local rockX = islandX + math.random(-islandSize/2, islandSize/2)
local rockZ = islandZ + math.random(-islandSize/2, islandSize/2)
local rockSize = math.random(2, 6)
Terrain:FillBall(
CFrame.new(rockX, -SAND_DEPTH + 5 + height + rockSize/2, rockZ),
Vector3.new(rockSize, rockSize, rockSize),
Enum.Material.Rock
)
end
end
end
-- Generate the world
generateCaves()
generateIslands()
-- Add some fish or other ocean life (optional)
local function addOceanLife()
for i = 1, 50 do
local fish = Instance.new("Part")
fish.Size = Vector3.new(2, 1, 0.5)
fish.Shape = Enum.PartType.Ball
fish.Material = Enum.Material.Neon
fish.Color = Color3.fromRGB(math.random(50, 200), math.random(50, 200), math.random(200, 255))
fish.Anchored = false
fish.CanCollide = false
fish.Position = Vector3.new(
math.random(-WORLD_SIZE/2, WORLD_SIZE/2),
math.random(-WATER_HEIGHT/2, WATER_HEIGHT/2),
math.random(-WORLD_SIZE/2, WORLD_SIZE/2)
)
fish.Parent = workspace
-- Simple movement for the fish
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = Vector3.new(math.random(-5, 5), 0, math.random(-5, 5))
bodyVelocity.MaxForce = Vector3.new(1000, 0, 1000)
bodyVelocity.Parent = fish
end
end
addOceanLife()
print("World generation complete!")
How to Use This Script:
- Open Roblox Studio and create a new baseplate game
- Go to ServerScriptService in the Explorer window
- Insert a new Script object
- Paste this entire script into it
- Click the Play button to test your world
Customization Options:
You can adjust these variables at the top of the script to change your world:
WORLD_SIZE: Makes the world bigger or smaller
WATER_HEIGHT: Changes how deep the water is
SAND_DEPTH: Changes how thick the sand layer is
CAVE_DEPTH: Changes how deep the caves are
ISLAND_COUNT: Changes how many islands are generated
The script includes:
- A large ocean with water
- Sand at the bottom
- A cave system under the sand
- Small islands with grass and rocks
- Some simple fish for ocean life
Would you like me to modify any part of this script or add additional features?