PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

BindableEvent

Show deprecated

BindableEvent

Show deprecated

Note: If a Table is passed as an argument to a BindableEvent it must be an array without missing entries or have string keys, not a mixture, or else the string keys will be lost. Allows events defined in one script to be subscribed to by another script. However, please note that BindableEvents do not allow for communication between the server and client. If you are looking for this functionality use RemoteEvent.


Properties

Inherited from Instance: Show Hide

bool

Archivable

Determines if an Instance can be cloned using /Instance/Clone or saved to file.

string

ClassName

[ReadOnly] [NotReplicated]

A read-only string representing the class this Instance belongs to

int

DataCost

[ReadOnly] [NotReplicated] [Deprecated]

The cost of saving the instance using data persistence.

string

Name

A non-unique identifier of the Instance

Instance

Parent

Determines the hierarchical parent of the Instance

bool

RobloxLocked

If true, the Instance and its descendants cannot be indexed or edited by a Script or LocalScript and will throw an error if it is attempted

bool

archivable

[Hidden] [NotReplicated] [Deprecated]
string

className

[ReadOnly] [NotReplicated] [Deprecated]

Functions

void

Fire ( Tuple arguments )

Fires the BindableEvent, which fires the “Event” event.

Inherited from Instance: Show Hide

void

ClearAllChildren ( )

This function destroys all of an Instance's children.

Instance

Clone ( )

Create a deep copy of a Roblox instance and descendants where Archivable = true.

void

Destroy ( )

Sets the Instance/Parent property to nil, locks the Instance/Parent property, disconnects all connections and calls Destroy on all children.

Instance

FindFirstAncestor ( string name )

Returns the first ancestor of the Instance whose Instance/Name is equal to the given name.

Instance

FindFirstAncestorOfClass ( string className )

Returns the first ancestor of the Instance whose Instance/ClassName is equal to the given className.

Instance

FindFirstAncestorWhichIsA ( string className )

Returns the first ancestor of the Instance for whom Instance/IsA returns true for the given className.

Instance

FindFirstChild ( string name , bool recursive )

Returns the first child of the Instance found with the given name.

Instance

FindFirstChildOfClass ( string className )

Returns the first child of the Instance whose Instance/ClassName|ClassName is equal to the given className.

Instance

FindFirstChildWhichIsA ( string className , bool recursive )

Returns the first child of the Instance for whom Instance/IsA returns true for the given className.

Variant

GetAttribute ( string attribute )

RBXScriptSignal

GetAttributeChangedSignal ( string attribute )

Dictionary

GetAttributes ( )

Objects

GetChildren ( )

Returns an array containing all of the Instance's children.

string

GetDebugId ( int scopeLength )

[NotBrowsable]

Returns a coded string of the Instances DebugId used internally by Roblox.

Array

GetDescendants ( )

[CustomLuaState]

Returns an array containing all of the descendants of the instance

string

GetFullName ( )

Returns a string describing the Instance's ancestry.

RBXScriptSignal

GetPropertyChangedSignal ( string property )

Get an event that fires when a given property of an object changes.

bool

IsA ( string className )

[CustomLuaState]

Returns true if an Instance's class matches or inherits from a given class

bool

IsAncestorOf ( Instance descendant )

Returns true if an Instance is an ancestor of the given descendant.

bool

IsDescendantOf ( Instance ancestor )

Returns true if an Instance is a descendant of the given ancestor.

void

Remove ( )

[Deprecated]

Sets the object’s Parent to nil, and does the same for all its descendants.

void

SetAttribute ( string attribute , Variant value )

Instance

WaitForChild ( string childName , double timeOut )

[CustomLuaState] [CanYield]

Returns the child of the Instance with the given name. If the child does not exist, it will yield the current thread until it does.

Objects

children ( )

[Deprecated]

Returns an array of the object’s children.

Instance

clone ( )

[Deprecated]
void

destroy ( )

[Deprecated]
Instance

findFirstChild ( string name , bool recursive )

[Deprecated]
Objects

getChildren ( )

[Deprecated]
bool

isA ( string className )

[Deprecated] [CustomLuaState]
bool

isDescendantOf ( Instance ancestor )

[Deprecated]
void

remove ( )

[Deprecated]

Events

RBXScriptSignal

Event ( Tuple arguments )

The event that is fired when Fire is called.

Inherited from Instance: Show Hide

RBXScriptSignal

AncestryChanged ( Instance child , Instance parent )

Fires when the Instance/Parent property of the object or one of its ancestors is changed.

RBXScriptSignal

AttributeChanged ( string attribute )

RBXScriptSignal

Changed ( string property )

Fired immediately after a property of an object changes.

RBXScriptSignal

ChildAdded ( Instance child )

Fires when an object is parented to this Instance.

RBXScriptSignal

ChildRemoved ( Instance child )

Fires when a child is removed from this Instance.

RBXScriptSignal

DescendantAdded ( Instance descendant )

Fires when a descendant is added to the Instance

RBXScriptSignal

DescendantRemoving ( Instance descendant )

Fires immediately before a descendant of the Instance is removed.

RBXScriptSignal

childAdded ( Instance child )

[Deprecated]

Code Samples


BindableEvent Valid Values

This code sample shows the kinds of values that can be sent when firing BindableEvents using Fire. Test this code by placing a Script within a BindableEvent inside the Workspace or ServerScriptService. It will raise errors on the values that cannot be fired.

local be = script.Parent

-- Define a simple function to connect
-- to the custom event
local function onEvent(...)
	print(...)
end
be.Event:Connect(onEvent)

-- These values CAN be sent when firing BindableEvents
be:Fire()           -- nil
be:Fire(25)         -- numbers
be:Fire("hello")    -- strings
be:Fire(true)       -- booleans
be:Fire("buy", 25)  -- multiple values are OK
be:Fire{1, 2, 3}    -- tables as arrays with no gaps
                      -- note the curly braces
be:Fire{            -- tables with string keys only
	hello = "world";
	goodbye = "world";
}
be:Fire{            -- tables with string keys
	point = {1, 2};   -- whose values are also valid
	point2 = {3, 4};
}
be:Fire{            -- tables as arrays
	{1, 2, 3};        -- whose values also are valid
	{hello = "world";};
}

-- These are some values you CANNOT send to/from BindableFunctions
be:Fire{1, nil, 3}  -- tables as arrays cannot have nil gaps
be:Fire{
	[{}] = "hello";   -- table keys can only be numbers OR strings
}
be:Fire{            -- tables keys cannot be BOTH numbers AND strings  
	[1] = "apple";
	hello = "world";
}

BindableEvent Theading Behavior

This code sample demonstrates how BindableEvents, like all Events, create threads of each connected function. Even if one errors, like ohNo does, the others continue. In addition, this sample shows how functions connected to the event can yield without blocking the thread that fired the event.

Test this code by pasting it into a Script within a BindableEvent parented to the Workspace or ServerScriptService. When running it, you’ll notice the error by ohNo does not stop the script from continuing (“Let’s-a-go!”) or any other connected function from being called. count and alphabet both do their tasks at the same time.

local be = script.Parent

-- Print numbers 1 through `n`
local function count(n)
	for i = 1, n do
		wait(.25)
		print(i)
	end
end

-- Print the first `n` letters of the alphabet
local function alphabet(n)
	for i = 0, n-1 do
		wait(.333)
		print(string.char(65+i))
	end
end

-- This function errors! But it doesn't stop
-- the others from being called
local function ohNo(n)
	if n > 10 then
		error("Oh no!")
	end
end

be.Event:Connect(count)
be.Event:Connect(alphabet)
be.Event:Connect(ohNo)
be:Fire(26)
print("Let's-a-go!")

BindableEvent Hello World

This code sample defines and connects a simple function to a BindableEvent. It then fires the BindableEvent, which in turn calls the connected function. It prints “Hello, world”. Test this script by pasting it into a BindableEvent within the Workspace or ServerScriptService.

local be = script.Parent

-- Define a simple function to connect
-- to the custom event
local function onEvent(...)
	print(...)
end
be.Event:Connect(onEvent)

-- Fire the event
be:Fire("Hello, world")