Experimental

An early preview: docs, the API and the dashboard may change or break.

Report a problem

types.Connection

Returned by connect; disconnecting twice does nothing.

Fields

connection.connected: boolean
#
read only

False once disconnected.

Methods

connection:disconnect()
#

Stops the handler from running again.

local players = require("@ember/players")
local world = require("@ember/world")

-- A handler that only runs for a while: a 30-second double-coins rush. `connect` returns a
-- connection; `disconnect` stops its handler, and the signal carries on for everyone else.
local function doubleCoins(seconds: number)
	local bonus = world.broken:connect(function(event)
		event.player.inventory:add("coin", 1)
	end)
	for _, player in players.all() do
		player:send(`<gold>Double coins for {seconds} seconds!`)
	end
	task.delay(seconds, function()
		bonus:disconnect()
		for _, player in players.all() do
			player:send("<gray>Double coins is over.")
		end
	end)
end

-- Every block broken pays one coin; during a rush the handler above pays a second.
world.broken:connect(function(event)
	event.player.inventory:add("coin", 1)
end)

task.delay(120, doubleCoins, 30)