Skip to main content

DropletManager

The DropletManager is the main entry point for the DropletSystem API. The DropletSystem is a system for creating, managing, and collecting droplets in your game. It aims to handle all the annoying parts of droplets for you, such as physics, collection, and replication. Once you create a new droplet type, spawning them is extremely easy.

To get started look at DropletServerManager's methods :RegisterResourceType and :Spawn. For more info on how to create a new droplet type, you can take a look at the included 'ExampleResourceTypeData' file, which will show you an example of a working ResourceType data table.

In order for the DropletSystem to work, you must have a Server and Client DropletManager, accessing them through this file on both server and client should initialize them so that replication can be established.

This file in particular exposes access to the Server and Client DropletManagers, Enums, and several common public types.


EXAMPLE USAGE:

[ExampleData.lua]

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DropletManager = require(ReplicatedStorage.DropletManager)

type Droplet = DropletManager.Droplet

return {
    Defaults = {
        LifeTime = NumberRange.new(20, 30);
    };

    SetupDroplet = function(droplet: Droplet): table?
        local Model = Instance.new("Model")
        Model.Name = "ExampleDroplet"

        local Part = Instance.new("Part")
        Part.Size = Vector3.one
        -- All attached parts should typically have these properties set to these values
        Part.Anchored = false
        Part.CanCollide = false
        Part.CanTouch = false
        Part.CanQuery = false
        Part.Massless = true

        Part.Parent = Model
        Model.PrimaryPart = Part

        droplet:AttachModel(Model)

        local SetupData = {
            Direction = if math.random() > 0.5 then 1 else -1 end;
        }
        return CustomData
    end;

    -- Ran when the droplet is within render range of the LocalPlayer's Camera
    OnRenderUpdate = function(droplet: Droplet, rendertimeElapsed: number): CFrame?
        local SetupData = droplet:GetSetupData()
        local OffsetCFrame = CFrame.new()

        local tPi = rendertimeElapsed * math.pi

        do -- Bobbing
            local AMPLITUDE = 1 -- Studs of vertical movement (+- half of this)
            local FREQUENCY = 0.25 -- Cycles per second
        
            local Y = (AMPLITUDE * 0.5) * -math.cos(tPi * (FREQUENCY))
            OffsetCFrame *= CFrame.new(0, AMPLITUDE + Y, 0)
        end

        do -- Rotating
            local TimeToMakeOneRotation = 4
            local RotationsPerSecond = 1/TimeToMakeOneRotation
            OffsetCFrame *= CFrame.Angles(0, tPi * RotationsPerSecond * SetupData.SpinDirection, 0)
        end

        return OffsetCFrame
    end;

    OnClientCollect = function(playerWhoCollected: Player, droplet: Droplet)
        print(playerWhoCollected, "collected droplet worth", droplet:GetValue())
    end;

    OnServerCollect = function(playerWhoCollected: Player, value: any)
        print(playerWhoCollected, "collected droplet worth", value)
    end;
}

Some Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DropletManager = require(ReplicatedStorage.DropletManager)
local ExampleData = require(ReplicatedStorage.ExampleData)

Droplets.Server:RegisterResourceType("Example", ExampleData) -- Register the Example ResourceType on the Server

while true do
    Droplets.Server:Spawn({
        ResourceType = "Example";
        Value = NumberRange.new(1, 5);
        Count = NumberRange.new(5, 10);
        SpawnPosition = Vector3.new(
            math.random(0, 10),
            5,
            math.random(0, 10)
        );
    })

    task.wait(1)
end

Some Client Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DropletManager = require(ReplicatedStorage.DropletManager)
local ExampleData = require(ReplicatedStorage.ExampleData)

DropletManager.Client:RegisterResourceType("Example", ExampleData) -- Register the Example ResourceType on the Client

Types

Droplet

type Droplet = Droplet

ResourceTypeData

type ResourceTypeData = ResourceTypeData

ResourceSpawnData

type ResourceSpawnData = ResourceSpawnData

Properties

Server

This item only works when running on the server. Server
DropletManager.Server: DropletServerManager

Accessing this will automatically create a new DropletServerManager if one does not exist.

Client

This item only works when running on the client. Client
DropletManager.Client: DropletClientManager

Accessing this will automatically create a new DropletClientManager if one does not exist.

Util

DropletManager.Util: DropletUtil
Show raw api
{
    "functions": [],
    "properties": [
        {
            "name": "Server",
            "desc": "Accessing this will automatically create a new DropletServerManager if one does not exist.",
            "lua_type": "DropletServerManager",
            "realm": [
                "Server"
            ],
            "source": {
                "line": 162,
                "path": "src/dropletmanager/src/Shared/DropletManager.lua"
            }
        },
        {
            "name": "Client",
            "desc": "Accessing this will automatically create a new DropletClientManager if one does not exist.",
            "lua_type": "DropletClientManager",
            "realm": [
                "Client"
            ],
            "source": {
                "line": 170,
                "path": "src/dropletmanager/src/Shared/DropletManager.lua"
            }
        },
        {
            "name": "Util",
            "desc": "",
            "lua_type": "DropletUtil",
            "source": {
                "line": 176,
                "path": "src/dropletmanager/src/Shared/DropletManager.lua"
            }
        }
    ],
    "types": [
        {
            "name": "Droplet",
            "desc": "",
            "lua_type": "Droplet",
            "source": {
                "line": 140,
                "path": "src/dropletmanager/src/Shared/DropletManager.lua"
            }
        },
        {
            "name": "ResourceTypeData",
            "desc": "",
            "lua_type": "ResourceTypeData",
            "source": {
                "line": 146,
                "path": "src/dropletmanager/src/Shared/DropletManager.lua"
            }
        },
        {
            "name": "ResourceSpawnData",
            "desc": "",
            "lua_type": "ResourceSpawnData",
            "source": {
                "line": 152,
                "path": "src/dropletmanager/src/Shared/DropletManager.lua"
            }
        }
    ],
    "name": "DropletManager",
    "desc": "The DropletManager is the main entry point for the DropletSystem API.\nThe DropletSystem is a system for creating, managing, and collecting droplets in your game.\nIt aims to handle all the annoying parts of droplets for you, such as physics, collection, and\nreplication. Once you create a new droplet type, spawning them is extremely easy.\n\nTo get started look at DropletServerManager's methods `:RegisterResourceType` and `:Spawn`.\nFor more info on how to create a new droplet type, you can take a look at the included\n'ExampleResourceTypeData' file, which will show you an example of a working ResourceType\ndata table.\n\nIn order for the DropletSystem to work, you must have a Server and Client DropletManager,\naccessing them through this file on both server and client should initialize them so that\nreplication can be established.\n\nThis file in particular exposes access to the Server and Client DropletManagers,\nEnums, and several common public types.\n\n----\nEXAMPLE USAGE:\n----\n\n[ExampleData.lua]\n```lua\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\nlocal DropletManager = require(ReplicatedStorage.DropletManager)\n\ntype Droplet = DropletManager.Droplet\n\nreturn {\n    Defaults = {\n        LifeTime = NumberRange.new(20, 30);\n    };\n\n    SetupDroplet = function(droplet: Droplet): table?\n        local Model = Instance.new(\"Model\")\n        Model.Name = \"ExampleDroplet\"\n\n        local Part = Instance.new(\"Part\")\n        Part.Size = Vector3.one\n        -- All attached parts should typically have these properties set to these values\n        Part.Anchored = false\n        Part.CanCollide = false\n        Part.CanTouch = false\n        Part.CanQuery = false\n        Part.Massless = true\n\n        Part.Parent = Model\n        Model.PrimaryPart = Part\n\n        droplet:AttachModel(Model)\n\n        local SetupData = {\n            Direction = if math.random() > 0.5 then 1 else -1 end;\n        }\n        return CustomData\n    end;\n\n    -- Ran when the droplet is within render range of the LocalPlayer's Camera\n    OnRenderUpdate = function(droplet: Droplet, rendertimeElapsed: number): CFrame?\n        local SetupData = droplet:GetSetupData()\n        local OffsetCFrame = CFrame.new()\n\n        local tPi = rendertimeElapsed * math.pi\n\n        do -- Bobbing\n            local AMPLITUDE = 1 -- Studs of vertical movement (+- half of this)\n            local FREQUENCY = 0.25 -- Cycles per second\n        \n            local Y = (AMPLITUDE * 0.5) * -math.cos(tPi * (FREQUENCY))\n            OffsetCFrame *= CFrame.new(0, AMPLITUDE + Y, 0)\n        end\n\n        do -- Rotating\n            local TimeToMakeOneRotation = 4\n            local RotationsPerSecond = 1/TimeToMakeOneRotation\n            OffsetCFrame *= CFrame.Angles(0, tPi * RotationsPerSecond * SetupData.SpinDirection, 0)\n        end\n\n        return OffsetCFrame\n    end;\n\n    OnClientCollect = function(playerWhoCollected: Player, droplet: Droplet)\n        print(playerWhoCollected, \"collected droplet worth\", droplet:GetValue())\n    end;\n\n    OnServerCollect = function(playerWhoCollected: Player, value: any)\n        print(playerWhoCollected, \"collected droplet worth\", value)\n    end;\n}\n```\n----\nSome Server Script:\n```lua\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\nlocal DropletManager = require(ReplicatedStorage.DropletManager)\nlocal ExampleData = require(ReplicatedStorage.ExampleData)\n\nDroplets.Server:RegisterResourceType(\"Example\", ExampleData) -- Register the Example ResourceType on the Server\n\nwhile true do\n    Droplets.Server:Spawn({\n        ResourceType = \"Example\";\n        Value = NumberRange.new(1, 5);\n        Count = NumberRange.new(5, 10);\n        SpawnPosition = Vector3.new(\n            math.random(0, 10),\n            5,\n            math.random(0, 10)\n        );\n    })\n\n    task.wait(1)\nend\n```\n----\nSome Client Script:\n```lua\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\nlocal DropletManager = require(ReplicatedStorage.DropletManager)\nlocal ExampleData = require(ReplicatedStorage.ExampleData)\n\nDropletManager.Client:RegisterResourceType(\"Example\", ExampleData) -- Register the Example ResourceType on the Client\n```",
    "source": {
        "line": 130,
        "path": "src/dropletmanager/src/Shared/DropletManager.lua"
    }
}