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

BindableEvent Valid Values

BindableEvent Valid Values

Oct 01 2018, 1:22 AM PST

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";
}