Skip to main content

NetworkOwnerService

Tracks a stack of owners so ownership isn't reverted or overwritten in delayed network owner set. Deduplicates network ownership handles.

Setup

-- Server.lua

local serviceBag = require("ServiceBag")
serviceBag:GetService(require("NetworkOwnerService"))

serviceBag:Init()
serviceBag:Start()

Usage

local networkOwnerService = serviceBag:GetService(NetworkOwnerService)

-- Force this part to be owned by the server
local handle = networkOwnerService:AddSetNetworkOwnerHandle(workspace.Part, nil)

delay(2.5, function()
	-- oh no, another function wants to set the network owner, guess we'll be owned by Quenty for a while
	local handle = networkOwnerService:AddSetNetworkOwnerHandle(workspace.Part, Players.Quenty)

	delay(1, function()
		-- stop using quenty, guess we're back to the server now
		handle()
	end)
end)

delay(5, function()
	handle() -- stop forcing network ownership to be the server, now we're back to nil
end)

Functions

Init

NetworkOwnerService:Init() → ()

Initializes the NetworkOwnerService. Should be done via ServiceBag.

AddSetNetworkOwnerHandle

NetworkOwnerService:AddSetNetworkOwnerHandle(
partBasePart,
playerPlayer
) → ()

Tries to set the network owner handle to the given player.

Show raw api
{
    "functions": [
        {
            "name": "Init",
            "desc": "Initializes the NetworkOwnerService. Should be done via [ServiceBag].",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 51,
                "path": "src/networkownerservice/src/Server/NetworkOwnerService.lua"
            }
        },
        {
            "name": "AddSetNetworkOwnerHandle",
            "desc": "Tries to set the network owner handle to the given player.",
            "params": [
                {
                    "name": "part",
                    "desc": "",
                    "lua_type": "BasePart"
                },
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 62,
                "path": "src/networkownerservice/src/Server/NetworkOwnerService.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "NetworkOwnerService",
    "desc": "Tracks a stack of owners so ownership isn't reverted or overwritten in delayed network owner set. Deduplicates network\nownership handles.\n\n## Setup\n```lua\n-- Server.lua\n\nlocal serviceBag = require(\"ServiceBag\")\nserviceBag:GetService(require(\"NetworkOwnerService\"))\n\nserviceBag:Init()\nserviceBag:Start()\n```\n\n## Usage\n```lua\nlocal networkOwnerService = serviceBag:GetService(NetworkOwnerService)\n\n-- Force this part to be owned by the server\nlocal handle = networkOwnerService:AddSetNetworkOwnerHandle(workspace.Part, nil)\n\ndelay(2.5, function()\n\t-- oh no, another function wants to set the network owner, guess we'll be owned by Quenty for a while\n\tlocal handle = networkOwnerService:AddSetNetworkOwnerHandle(workspace.Part, Players.Quenty)\n\n\tdelay(1, function()\n\t\t-- stop using quenty, guess we're back to the server now\n\t\thandle()\n\tend)\nend)\n\ndelay(5, function()\n\thandle() -- stop forcing network ownership to be the server, now we're back to nil\nend)\n```",
    "source": {
        "line": 40,
        "path": "src/networkownerservice/src/Server/NetworkOwnerService.lua"
    }
}