M MY Multiplayer: Wiki
Side
Kind

removeEventHandler

Shared

Takes a function off an element's event, where addEventHandler put it.

bool removeEventHandler(string eventName, element attachedTo, function handler)

Parameters

NameTypeDescription
eventNamestringThe event's name.
attachedToelementThe same element given to addEventHandler.
handlerfunctionThe same function given to addEventHandler.

Returns

true if it was removed, false if that function was not on that event of that element.

A handler removed while the event is already running is not called for the rest of that trigger.

Example

local function onFirstSpawn()
    outputDebugString(getPlayerName(source) .. " spawned for the first time")
    removeEventHandler("onPlayerSpawn", source, onFirstSpawn)
end

addEventHandler("onPlayerJoin", root, function()
    addEventHandler("onPlayerSpawn", source, onFirstSpawn)
end)

See also