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

SetCore

SetCore (not to be confused with StarterGui/SetCoreGuiEnabled|SetCoreGuiEnabled) exposes a variety of functionality defined by Roblox’s CoreScripts, such as sending notifications, toggling notifications for badges/points, defining a callback for the reset button or toggling the topbar. The first parameter to SetCore is a string that selects the functionality with which the call will interact: a CoreScript must have registered such a string already (if one hasn’t, an error is raised). It may be necessary to make multiple calls to SetCore using pcall in case the respective CoreScript has yet to load (or if it has been disabled entirely).

The following table describes the strings that may be accepted as the first parameter in a call to SetCore. The parameters that should follow are dependent on the functionality that will be used and are described in sub-tables.

ChatActive

Controls whether the chat is active

#NameTypeDefaultDescription
2activeboolRequiredDetermines whether the chat should be made active

PointsNotificationsActive

Controls whether notifications for earned player points will appear

#NameTypeDefaultDescription
2activeboolRequiredDetermines whether notifications for earned player points will appear

BadgeNotificationsActive

Controls whether notifications for earned badges will appear

#NameTypeDefaultDescription
2activeboolRequiredDetermines whether notifications for earned badges will appear

ResetButtonCallback

Determines the behavior, if any, of the reset button given a bool or a BindableEvent to be BindableEvent/Fire|fired when a player requests to reset.

#NameTypeDefaultDescription
2enabledboolRequiredDetermines whether the reset button retains its default behavior
OR
2callback

BindableEvent

RequiredA BindableEvent to be fired when the player confirms they want to reset

ChatMakeSystemMessage

Display a formatted message in the chat.

#NameTypeDefaultDescription
2configTabledictionaryRequiredA dictionary of information describing the message (see below)
NameTypeDefaultDescription
TextstringRequiredThe message to display
Color

DataType/Color3

Color3.fromRGB(255, 255, 243)

The TextLabel/TextColor3|TextColor3 of the message

FontEnum.FontSourceSansBold

The TextLabel/Font|Font of the message

FontSizeEnum.FontSizeSize24

The TextLabel/FontSize|FontSize of the message

ChatWindowSize

Determines the GuiObject/Size|size of the chat window.

#NameTypeDefaultDescription
2windowSize

DataType/UDim2

Required

Determines the GuiObject/Size|size of the chat window

ChatWindowPosition

Determines the GuiObject/Position|position of the chat window.

#NameTypeDefaultDescription
2windowPosition

DataType/UDim2

Required

Determines the GuiObject/Position|position of the chat window

ChatBarDisabled

Determines whether the player is able to type a message into the chat.

#NameTypeDefaultDescription
2disabledboolRequired

Determines whether the chat’s TextBox input is GuiObject/Visible|visible.

SendNotification

Causes a non-intrusive notification to appear at the bottom right of the screen. The notification may have up to two buttons.

#NameTypeDefaultDescription
2configTabledictionaryRequiredA dictionary of information describing the notification (see below)
NameTypeDefaultDescription
TitlestringRequiredThe title of the notification
TextstringRequiredThe main text of the notification
IconstringOptional

The ImageLabel/Image|Image to display with the notification

Durationnumber5Duration (in seconds) the notification should stay visible
Callback

BindableFunction

Optional

A BindableFunction that should be BindableFunction/Invoke|invoked with the text of the button pressed by the player.

Button1stringOptionalThe text to display on the first button
Button2stringOptionalThe text to display on the second button

TopbarEnabled

Determines whether the topbar is displayed. Disabling the topbar will also disable all CoreGuis, such as the chat, inventory and player list (i.e. those set with StarterGui/SetCoreGuiEnabled|SetCoreGuiEnabled).

When disabled, the region the topbar once occupied will still capture mouse events; however, TextButton|buttons placed there will not respond to GuiButton/MouseButton1Click|clicks. The origin of GUI space will still be offset 36 pixels from the top of the screen.

#NameTypeDefaultDescription
2enabledboolRequiredDetermines whether the topbar should be visible

DeveloperConsoleVisible

Determines whether the Developer Console is GuiObject/Visible|visible.

#NameTypeDefaultDescription
2visibilityboolRequired

Determines whether the developer console is GuiObject/Visible|visible

PromptSendFriendRequest

Prompts the current player to send a friend request to the given Player.

#NameTypeDefaultDescription
2player

Player

Required

The Player to which the friend request should be sent

PromptUnfriend

Prompts the current player to remove a given Player from their friends list.

#NameTypeDefaultDescription
2player

Player

Required

The Player who should be unfriended

PromptBlockPlayer

Prompts the current player to block the given Player.

#NameTypeDefaultDescription
2player

Player

Required

The Player who should be blocked

PromptUnblockPlayer

Prompts the current player to unblock the given Player.

#NameTypeDefaultDescription
2player

Player

Required

The Player who should be unblocked

SetAvatarContextMenuEnabled

Determines whether the Avatar Context Menu is enabled.

#NameTypeDefaultDescription
2enabledboolRequiredDetermines whether the Avatar Context Menu is enabled

AddAvatarContextMenuOption

Adds an option to the Avatar Context Menu.

#NameTypeDefaultDescription
2optionEnum.AvatarContextMenuOptionRequiredFriend (send friend request), Chat (start private chat), or Emote (wave)
OR
2optiontableRequired

A two-element table, where the first is the name of the custom action, and the second is a BindableEvent which will be BindableEvent/Fire|fired with a player was selected when the option was activated.

RemoveAvatarContextMenuOption

Removes an option to the Avatar Context Menu. The option argument must be the same as what was used with AddAvatarContextMenuOption (see above).

#NameTypeDefaultDescription
2optionVariantRequiredThe same value provided to AddAvatarContextMenuOption

CoreGuiChatConnections

Sets up a bindable gateway connection between the CoreGui topbar’s chat button and the Lua Chat System. The second parameter must be a table of BindableEvent|BindableEvents and BindableFunction|BindableFunctions. See the example below for more clarification.

-- Create the Bindable objects
local ChatConnections = {}
 
local function AddObjects(bindableClass,targetName,...)
	local target = ChatConnections[targetName]
	if not target then
		target = {}
		ChatConnections[targetName] = target
	end
	local names = {...}
	for _,name in pairs(names) do
		local signal = Instance.new(bindableClass)
		signal.Name = targetName .. "_" .. name
		signal.Parent = script
		target[name] = signal
	end
end
 
AddObjects("BindableEvent","ChatWindow",
	---------------------------
	-- Fired from the CoreGui
	---------------------------
	"ToggleVisibility", -- Fired when the CoreGui chat button is pressed.
	"SetVisible", -- Fired when the CoreGui wants to directly change the visiblity state of the chat window.
	"FocusChatBar", -- Fired when the CoreGui wants to capture the Chatbar's Focus.
	"TopbarEnabledChanged", -- Fired when the visibility of the Topbar is changed.
	"SpecialKeyPressed", -- Fired when the reserved ChatHotkey is pressed.
	"CoreGuiEnabled", -- Fired when a user changes the SetCoreGuiEnabled state of the Chat Gui.
 
	---------------------------
	-- Fired to the CoreGui
	---------------------------
	"ChatBarFocusChanged",
		-- ^ Fire this with 'true' when you want to assure the CoreGui that the ChatBar is being focused on.
 
	"VisibilityStateChanged", 
		-- ^ Fire this with 'true' when the user shows or hides the chat.
 
	"MessagesChanged",
		-- ^ Fire this with a number to change the number of messages that have been recorded by the chat window.
		--   If the CoreGui thinks the chat window isn't visible, it will display the recorded difference between
		--   the number of messages that was displayed when it was visible, and the number you supply.
 
	"MessagePosted" 
		-- ^ Fire this to make the player directly chat under Roblox's C++ API. 
		--	 This will fire the LocalPlayer's Chatted event.
		--   Please only fire this on the player's behalf. If you attempt to spoof a player's chat
		--   to get them in trouble, you could face serious moderation action.
)
 
AddObjects("BindableFunction","ChatWindow",
	"IsFocused" -- This will be invoked by the CoreGui when it wants to check if the chat window is active.
)
 
-- The following events are fired if the user calls StarterGui:SetCore(string name, Variant data)
-- Note that you can only hook onto these ones specifically.
AddObjects("BindableEvent","SetCore",
	"ChatMakeSystemMessage",
	"ChatWindowPosition",
	"ChatWindowSize",
	"ChatBarDisabled"
)
 
-- The following functions are invoked if the user calls StarterGui:GetCore(string name)
-- Note that you can only hook onto these ones specifically.
AddObjects("BindableFunction","GetCore",
	"ChatWindowPosition", -- Should return a UDim2 representing the position of the chat window.
	"ChatWindowSize", -- Should return a UDim2 representing the size of the chat window.
	"ChatBarDisabled" -- Should return true if the chat bar is currently disabled.
)
 
-- Connect ChatConnections to the CoreGui.
local StarterGui = game:GetService("StarterGui")
local tries = 0
local maxAttempts = 10
 
while (tries < maxAttempts) do
	local success,result = pcall(function ()
		StarterGui:SetCore("CoreGuiChatConnections",ChatConnections)
	end)
	if success then
		break
	else
		tries = tries + 1
		if tries == maxAttempts then
			error("Error calling SetCore CoreGuiChatConnections: " .. result)
		else
			wait()
		end
	end
end
 
while wait(0.2) do
	local isVisible = (math.random() > 0.5)
	ChatConnections.ChatWindow.VisibilityStateChanged:Fire(isVisible)
	if not isVisible then
		local messageCount = math.random(1,120)
		ChatConnections.ChatWindow.MessagesChanged:Fire(messageCount)
	end
end

Parameters

Name Type Default Description

Selects the functionality with which the call will interact: a CoreScript must have registered such a string already (if one hasn’t, an error is raised)

A table of BindableEvent|BindableEvents and BindableFunction|BindableFunctions

Returns

Return Type Summary

No return


Code Samples


StarterGui:SetCore

local resetBindable = Instance.new("BindableEvent")
resetBindable.Event:Connect(function()
    -- Implement custom reset logic here
end)

-- This will remove the current behavior for when the reset button 
-- is pressed and just fire resetBindable instead.
game:GetService("StarterGui"):SetCore("ResetButtonCallback", resetBindable)

-- Setting ResetButtonCallback to false will grey out the reset button
-- in the menu and players won't be able to reset in your game.
game:GetService("StarterGui"):SetCore("ResetButtonCallback", false)