Skip to main content

Ocean

The module itself: require(game.ReplicatedStorage.Ocean). Everything you need day to day is here: weather, zones, water queries, water events and tag helpers. The other classes are the pieces it is built from; reach for them only when you need something lower level.

local Ocean = require(game.ReplicatedStorage.Ocean)

-- server: define a weather and cross-fade the whole sea into it over 20 seconds
Ocean:CreateWeather("Rough", Ocean.Presets.Ocean["Pirate Seas"])
Ocean:SetWeather("Rough", 20)

-- anywhere: where is the surface right now?
local y = Ocean:GetHeight(boat.Position)

Settings are attributes on the module (see Settings); the server owns them and they replicate. The bootstrap scripts the plugin installs call Ocean.Init once on the server and once on every client, so you never have to.

Properties​

Settings​

Ocean.Settings: Settings

The settings spec and accessors.

Waves​

Ocean.Waves: Waves

The wave function: heights, displacement, obstacles.

Weather​

Ocean.Weather: Weather

The replicated weather state.

Presets​

Ocean.Presets: Presets

Ready-made physics, looks and whole oceans.

Regions​

Ocean.Regions: Regions

Dry regions (OceanDry).

Tracker​

Ocean.Tracker: Tracker

Per-instance water state.

Zones​

Ocean.Zones: Zones

Tagged OceanZone areas.

Tags​

Ocean.Tags: {
Float: string,
Obstacle: string,
Dry: string,
Track: string
}

The current tag names (they follow the FloatTag, ObstacleTag, DryTag and TrackTag settings).

EnteredWater​

Ocean.EnteredWater: RBXScriptSignal<Instance>

Fires when a tracked instance or character goes from dry to touching the water.

ExitedWater​

Ocean.ExitedWater: RBXScriptSignal<Instance>

Fires when a tracked instance or character leaves the water entirely.

WentUnderWater​

Ocean.WentUnderWater: RBXScriptSignal<Instance>

Fires when a tracked instance or character becomes fully submerged.

WentAboveWater​

Ocean.WentAboveWater: RBXScriptSignal<Instance>

Fires when a fully submerged instance or character surfaces again.

Functions​

Init​

Ocean.Init() → ()

Starts the ocean on this side: reads the settings, compiles the weather, starts obstacle and zone tracking, water events and (on a client) the renderer. Safe to call more than once. The installed OceanServer and OceanClient scripts already do this.

CreateWeather​

This item only works when running on the server. Server
Ocean:CreateWeather(
name: string,--

any name except "Default"

overrides: {[string]: any}--

setting name to value

) → ()

Defines (or redefines) a named weather: a table of setting overrides, keyed by setting name. Only settings marked as weather settings count (waves, colours, foam, spray, the underwater tint); anything else in the table is ignored, so an entry of Presets.Ocean can be passed straight in.

Ocean:CreateWeather("Storm", Ocean.Presets.Ocean["Pirate Seas"])
Ocean:CreateWeather("Glassy", { WaveHeight = 0.2, FoamOpacity = 0 })

SetWeather​

This item only works when running on the server. Server
Ocean:SetWeather(
name: string,
transition: number?--

seconds to fade over (default 0)

) → ()

Cross-fades the whole sea to a weather created with Ocean:CreateWeather, or back to "Default" (the module's own attribute values). The fade is a function of server time, so every client and the server physics stay in step.

GetWeather​

Ocean:GetWeather() → string

The name of the weather the whole sea is in (or fading toward).

CreateZone​

This item only works when running on the server. Server
Ocean:CreateZone(
name: string,
zone: {
Position: Vector3,
Radius: number,
Blend: number?,
Weather: string
}--

Blend defaults to 35% of the radius

) → ()

Creates a scripted weather zone: a disc of ocean with its own weather, blended into the surrounding sea across Blend studs at its rim. For zones built in Studio, tag a part OceanZone instead (see Zones).

SetZoneWeather​

This item only works when running on the server. Server
Ocean:SetZoneWeather(
name: string,--

the zone

weatherName: string,
transition: number?--

seconds (default 0)

) → ()

Cross-fades one scripted zone to another weather.

RemoveZone​

This item only works when running on the server. Server
Ocean:RemoveZone(name: string) → ()

Removes a scripted zone; the global weather takes over there.

GetHeight​

Ocean:GetHeight(position: Vector3) → number

World Y of the surface directly above or below the point, right now. Works on both sides and accounts for weather, zones, obstacles and FlatSea.

GetWaterHeight​

Ocean:GetWaterHeight(position: Vector3) → number

Alias of Ocean:GetHeight.

GetDepth​

Ocean:GetDepth(position: Vector3) → number

How far below the surface the point is. Negative means above the water. Ignores dry regions.

IsUnderWater​

Ocean:IsUnderWater(position: Vector3) → boolean

True when the point is below the surface and not inside a dry region.

IsAboveWater​

Ocean:IsAboveWater(position: Vector3) → boolean

The opposite of Ocean:IsUnderWater.

IsDry​

Ocean:IsDry(position: Vector3) → boolean

True inside an OceanDry region (a submarine interior, an underwater room).

GetSurfaceNormal​

Ocean:GetSurfaceNormal(position: Vector3) → Vector3

The surface normal at the point, sampled from the height field. Use it to align boats, decals or spray.

GetWaterState​

Ocean:GetWaterState(instance: Instance) → Tracker.State?

The current water state of a tracked instance (tagged OceanFloat or OceanTrack, or a player character), or nil if it is not tracked.

IsInWater​

Ocean:IsInWater(instance: Instance) → boolean

True when any part of a tracked instance is in the water.

GetInstancesInWater​

Ocean:GetInstancesInWater() → {Instance}

Every tracked instance that is currently in the water.

AddFloat​

Ocean:AddFloat(part: BasePart) → ()

Tags a part to float (the plugin's Buoyancy addon does the physics). Plain CollectionService tags underneath, so part:AddTag("OceanFloat") does the same.

RemoveFloat​

Ocean:RemoveFloat(part: BasePart) → ()

Removes the float tag.

AddObstacle​

Ocean:AddObstacle(instance: Instance) → ()

Tags a part or model as an obstacle: the sea calms against it. The OceanShore and OceanCalmness attributes on the instance tune the effect.

RemoveObstacle​

Ocean:RemoveObstacle(instance: Instance) → ()

Removes the obstacle tag.

AddDryRegion​

Ocean:AddDryRegion(instance: Instance) → ()

Tags a part or model as a dry region: no water inside its box.

RemoveDryRegion​

Ocean:RemoveDryRegion(instance: Instance) → ()

Removes the dry-region tag.

Track​

Ocean:Track(instance: Instance) → ()

Gets water events and Ocean:GetWaterState for an instance without floating it.

Untrack​

Ocean:Untrack(instance: Instance) → ()

Stops tracking an instance.

GetZoneAt​

Ocean:GetZoneAt(position: Vector3) → string?

The name of the OceanZone whose box contains the point, or nil.

GetZones​

Ocean:GetZones() → {string}

The names of every OceanZone in the place.

GetWeatherAt​

Ocean:GetWeatherAt(position: Vector3) → string

The name of the weather with the most influence at a point, zones included.

Show raw api
{
    "functions": [
        {
            "name": "Init",
            "desc": "Starts the ocean on this side: reads the settings, compiles the weather, starts obstacle and zone\ntracking, water events and (on a client) the renderer. Safe to call more than once. The installed\n`OceanServer` and `OceanClient` scripts already do this.",
            "params": [],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 150,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "CreateWeather",
            "desc": "Defines (or redefines) a named weather: a table of setting overrides, keyed by setting name. Only\nsettings marked as weather settings count (waves, colours, foam, spray, the underwater tint);\nanything else in the table is ignored, so an entry of [Presets.Ocean] can be passed straight in.\n\n```lua\nOcean:CreateWeather(\"Storm\", Ocean.Presets.Ocean[\"Pirate Seas\"])\nOcean:CreateWeather(\"Glassy\", { WaveHeight = 0.2, FoamOpacity = 0 })\n```",
            "params": [
                {
                    "name": "name",
                    "desc": "any name except \"Default\"",
                    "lua_type": "string"
                },
                {
                    "name": "overrides",
                    "desc": "setting name to value",
                    "lua_type": "{ [string]: any }"
                }
            ],
            "returns": [],
            "function_type": "method",
            "realm": [
                "Server"
            ],
            "source": {
                "line": 182,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "SetWeather",
            "desc": "Cross-fades the whole sea to a weather created with [Ocean:CreateWeather], or back to `\"Default\"`\n(the module's own attribute values). The fade is a function of server time, so every client and the\nserver physics stay in step.",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "transition",
                    "desc": "seconds to fade over (default 0)",
                    "lua_type": "number?"
                }
            ],
            "returns": [],
            "function_type": "method",
            "realm": [
                "Server"
            ],
            "source": {
                "line": 195,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "GetWeather",
            "desc": "The name of the weather the whole sea is in (or fading toward).",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 204,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "CreateZone",
            "desc": "Creates a scripted weather zone: a disc of ocean with its own weather, blended into the surrounding\nsea across `Blend` studs at its rim. For zones built in Studio, tag a part `OceanZone` instead\n(see [Zones]).",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "zone",
                    "desc": "`Blend` defaults to 35% of the radius",
                    "lua_type": "{ Position: Vector3, Radius: number, Blend: number?, Weather: string }"
                }
            ],
            "returns": [],
            "function_type": "method",
            "realm": [
                "Server"
            ],
            "source": {
                "line": 217,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "SetZoneWeather",
            "desc": "Cross-fades one scripted zone to another weather.",
            "params": [
                {
                    "name": "name",
                    "desc": "the zone",
                    "lua_type": "string"
                },
                {
                    "name": "weatherName",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "transition",
                    "desc": "seconds (default 0)",
                    "lua_type": "number?"
                }
            ],
            "returns": [],
            "function_type": "method",
            "realm": [
                "Server"
            ],
            "source": {
                "line": 229,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "RemoveZone",
            "desc": "Removes a scripted zone; the global weather takes over there.",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [],
            "function_type": "method",
            "realm": [
                "Server"
            ],
            "source": {
                "line": 239,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "GetHeight",
            "desc": "World Y of the surface directly above or below the point, right now. Works on both sides and\naccounts for weather, zones, obstacles and `FlatSea`.",
            "params": [
                {
                    "name": "position",
                    "desc": "",
                    "lua_type": "Vector3"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 250,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "GetWaterHeight",
            "desc": "Alias of [Ocean:GetHeight].",
            "params": [
                {
                    "name": "position",
                    "desc": "",
                    "lua_type": "Vector3"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 265,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "GetDepth",
            "desc": "How far below the surface the point is. Negative means above the water. Ignores dry regions.",
            "params": [
                {
                    "name": "position",
                    "desc": "",
                    "lua_type": "Vector3"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 276,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "IsUnderWater",
            "desc": "True when the point is below the surface and not inside a dry region.",
            "params": [
                {
                    "name": "position",
                    "desc": "",
                    "lua_type": "Vector3"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 286,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "IsAboveWater",
            "desc": "The opposite of [Ocean:IsUnderWater].",
            "params": [
                {
                    "name": "position",
                    "desc": "",
                    "lua_type": "Vector3"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 296,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "IsDry",
            "desc": "True inside an `OceanDry` region (a submarine interior, an underwater room).",
            "params": [
                {
                    "name": "position",
                    "desc": "",
                    "lua_type": "Vector3"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 307,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "GetSurfaceNormal",
            "desc": "The surface normal at the point, sampled from the height field. Use it to align boats, decals or spray.",
            "params": [
                {
                    "name": "position",
                    "desc": "",
                    "lua_type": "Vector3"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Vector3"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 318,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "GetWaterState",
            "desc": "The current water state of a tracked instance (tagged `OceanFloat` or `OceanTrack`, or a player\ncharacter), or nil if it is not tracked.",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Tracker.State?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 333,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "IsInWater",
            "desc": "True when any part of a tracked instance is in the water.",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 343,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "GetInstancesInWater",
            "desc": "Every tracked instance that is currently in the water.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ Instance }"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 353,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "AddFloat",
            "desc": "Tags a part to float (the plugin's Buoyancy addon does the physics). Plain CollectionService tags\nunderneath, so `part:AddTag(\"OceanFloat\")` does the same.",
            "params": [
                {
                    "name": "part",
                    "desc": "",
                    "lua_type": "BasePart"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 364,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "RemoveFloat",
            "desc": "Removes the float tag.",
            "params": [
                {
                    "name": "part",
                    "desc": "",
                    "lua_type": "BasePart"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 373,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "AddObstacle",
            "desc": "Tags a part or model as an obstacle: the sea calms against it. The `OceanShore` and\n`OceanCalmness` attributes on the instance tune the effect.",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 383,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "RemoveObstacle",
            "desc": "Removes the obstacle tag.",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 392,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "AddDryRegion",
            "desc": "Tags a part or model as a dry region: no water inside its box.",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 401,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "RemoveDryRegion",
            "desc": "Removes the dry-region tag.",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 410,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "Track",
            "desc": "Gets water events and [Ocean:GetWaterState] for an instance without floating it.",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 420,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "Untrack",
            "desc": "Stops tracking an instance.",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 429,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "GetZoneAt",
            "desc": "The name of the `OceanZone` whose box contains the point, or nil.",
            "params": [
                {
                    "name": "position",
                    "desc": "",
                    "lua_type": "Vector3"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 440,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "GetZones",
            "desc": "The names of every `OceanZone` in the place.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ string }"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 450,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "GetWeatherAt",
            "desc": "The name of the weather with the most influence at a point, zones included.",
            "params": [
                {
                    "name": "position",
                    "desc": "",
                    "lua_type": "Vector3"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 464,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "Preview",
            "desc": "Used by the Studio plugin to render the sea in Edit mode.",
            "params": [
                {
                    "name": "host",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "into",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [],
            "function_type": "static",
            "private": true,
            "source": {
                "line": 483,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "StopPreview",
            "desc": "Stops an Edit-mode preview.",
            "params": [],
            "returns": [],
            "function_type": "static",
            "private": true,
            "source": {
                "line": 496,
                "path": "packages/src/Ocean/init.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "Settings",
            "desc": "The settings spec and accessors.",
            "lua_type": "Settings",
            "source": {
                "line": 64,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "Waves",
            "desc": "The wave function: heights, displacement, obstacles.",
            "lua_type": "Waves",
            "source": {
                "line": 69,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "Weather",
            "desc": "The replicated weather state.",
            "lua_type": "Weather",
            "source": {
                "line": 74,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "Presets",
            "desc": "Ready-made physics, looks and whole oceans.",
            "lua_type": "Presets",
            "source": {
                "line": 79,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "Regions",
            "desc": "Dry regions (`OceanDry`).",
            "lua_type": "Regions",
            "source": {
                "line": 84,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "Tracker",
            "desc": "Per-instance water state.",
            "lua_type": "Tracker",
            "source": {
                "line": 89,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "Zones",
            "desc": "Tagged `OceanZone` areas.",
            "lua_type": "Zones",
            "source": {
                "line": 94,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "Tags",
            "desc": "The current tag names (they follow the `FloatTag`, `ObstacleTag`, `DryTag` and `TrackTag` settings).",
            "lua_type": "{ Float: string, Obstacle: string, Dry: string, Track: string }",
            "source": {
                "line": 99,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "EnteredWater",
            "desc": "Fires when a tracked instance or character goes from dry to touching the water.",
            "lua_type": "RBXScriptSignal<Instance>",
            "source": {
                "line": 104,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "ExitedWater",
            "desc": "Fires when a tracked instance or character leaves the water entirely.",
            "lua_type": "RBXScriptSignal<Instance>",
            "source": {
                "line": 109,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "WentUnderWater",
            "desc": "Fires when a tracked instance or character becomes fully submerged.",
            "lua_type": "RBXScriptSignal<Instance>",
            "source": {
                "line": 114,
                "path": "packages/src/Ocean/init.luau"
            }
        },
        {
            "name": "WentAboveWater",
            "desc": "Fires when a fully submerged instance or character surfaces again.",
            "lua_type": "RBXScriptSignal<Instance>",
            "source": {
                "line": 119,
                "path": "packages/src/Ocean/init.luau"
            }
        }
    ],
    "types": [],
    "name": "Ocean",
    "desc": "The module itself: `require(game.ReplicatedStorage.Ocean)`. Everything you need day to day is here:\nweather, zones, water queries, water events and tag helpers. The other classes are the pieces it is\nbuilt from; reach for them only when you need something lower level.\n\n```lua\nlocal Ocean = require(game.ReplicatedStorage.Ocean)\n\n-- server: define a weather and cross-fade the whole sea into it over 20 seconds\nOcean:CreateWeather(\"Rough\", Ocean.Presets.Ocean[\"Pirate Seas\"])\nOcean:SetWeather(\"Rough\", 20)\n\n-- anywhere: where is the surface right now?\nlocal y = Ocean:GetHeight(boat.Position)\n```\n\nSettings are attributes on the module (see [Settings]); the server owns them and they replicate.\nThe bootstrap scripts the plugin installs call [Ocean.Init] once on the server and once on every\nclient, so you never have to.",
    "source": {
        "line": 59,
        "path": "packages/src/Ocean/init.luau"
    }
}