API:Class/StarterGui/SetCore

Note:This feature will only work in a LocalScript (or a ModuleScript running on the client)


SetCore

Function of StarterGui icon.pngStarterGui
void SetCore (
    string parameterName,
    Variant value
)
Parameters:
  1. parameterName
  2. value

Returns: void
Description: Allows you to perform certain interactions with Roblox's CoreScripts.

ChatActive

void StarterGui:SetCore("ChatActive", bool active)

Description:
Sets if the chat is active or not

PointsNotificationsActive

void StarterGui:SetCore("PointsNotificationsActive", bool active)

Description:
Sets whether a notification should be shown when a player gains or loses player points.

BadgeNotificationsActive

void StarterGui:SetCore("BadgesNotificationsActive", bool active)

Description:
Sets whether a notification should be shown when a player earns a badge.

ResetButtonCallback

void StarterGui:SetCore("ResetButtonCallback", Variant<bool, BindableEvent> enabledOrCallback)

Description:
If provided with a bool, this sets the enabled state of the menu's reset button. If set to a BindableEvent, the event will be fired when the user confirms that they want to reset, rather than performing the default callback where it kills the player's character.


Example:
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)

ChatMakeSystemMessage

void StarterGui:SetCore("ChatMakeSystemMessage", dictionary<Variant> configTable)

Description:
Allows you to add messages to the chat, like the help message that appears when you join a game.

Example:
The following code would say "Welcome to my game!" in the chat, colored cyan:

game.StarterGui:SetCore("ChatMakeSystemMessage", {
	Text = "Welcome to my game!"; -- Required. Has to be a string!
	Color = Color3.new(0, 1, 1); -- Cyan is (0, 255 / 255, 255 / 255). Optional, defaults to white: Color3.new(255 / 255, 255 / 255, 243 / 255)
	Font = Enum.Font.SourceSans; -- Optional, defaults to Enum.Font.SourceSansBold
	FontSize = Enum.FontSize.Size24; -- Optional, defaults to Enum.FontSize.Size18
})

ChatWindowSize

void StarterGui:SetCore("ChatWindowSize", UDim2 windowSize)

Description:
Sets the size of the chat window.

ChatWindowPosition

void StarterGui:SetCore("ChatWindowPosition", UDim2 windowPosition)

Description:
Sets the position of the chat window.

ChatBarDisabled

void StarterGui:SetCore("ChatBarDisabled", bool disabled)

Description:
Sets whether or not the chat bar is disabled.

SendNotification

void StarterGui:SetCore("SendNotification", dictionary<Variant> configTable)

Description:
Makes a notification pop up.

Example:
The following code would make a notification with the title "Welcome to my game!", asking the user if they want extra points. When the user selects 'Yes' or 'No', the callback function will be called with "Yes" or "No". In case the user presses no button, the callback won't be fired.

local function callback(text)
	if text == "Yes" then
		print("They want extra points!")
	elseif text == "No" then
		print("They don't care...")
	end
end
 
local bindableFunction = Instance.new("BindableFunction")
bindableFunction.OnInvoke = callback
 
game.StarterGui:SetCore("SendNotification", {
	Title = "Welcome to my game!"; -- Required. Has to be a string!
	Text = "Do you want extra points?"; -- Required. Has to be a string!
	Icon = ""; -- Optional, defaults to "" (no icon)
	Duration = 5; -- Optional, defaults to 5 seconds
	Callback = bindableFunction; -- Optional, gets invoked with the text of the button the user pressed
	Button1 = "Yes"; -- Optional, makes a button appear with the given text that, when clicked, fires the Callback if it's given
	Button2 = "No"; -- Optional, makes another button appear with the given text that, when clicked, fires the Callback if it's given
})

TopbarEnabled

void StarterGui:SetCore("TopbarEnabled", bool enabled)

Description:
Whether to display the topbar or not. The region it occupied will still capture mouse events; buttons placed there will not respond to clicks.

DeveloperConsoleVisible

void StarterGui:SetCore("DeveloperConsoleVisible", bool visibility)

Description:
Toggle developer console visibility.

PromptSendFriendRequest

void StarterGui:SetCore("PromptSendFriendRequest", Player player)

Description:
Prompts the current user to send a friend request to another player.

PromptUnfriend

void StarterGui:SetCore("PromptUnfriend", Player player)

Description:
Prompts the current user to unfriend another player.

PromptBlockPlayer

void StarterGui:SetCore("PromptBlockPlayer", Player player)

Description:
Prompts the current user to block another player.

PromptUnblockPlayer

void StarterGui:SetCore("PromptUnblockPlayer", Player player)

Description:
Prompts the current user to unblock another player.

CoreGuiChatConnections

void StarterGui:SetCore("CoreGuiChatConnections", dictionary<dictionary<Variant<BindableEvent, BindableFunction>>> chatConnections)

Description:
Sets up a bindable gateway connection between the CoreGui Topbar's chat button and the Lua Chat System.
This expects a specific dictionary setup of ExplorerImageIndex67.pngBindableEvents and Function Icon.pngBindableFunctions.
See the example below for more clarification.

Example:
The following example correctly sets up the CoreGuiChatConnections, and then causes the chat icon to rapidly switch between blue and white with a varying message count. Note that this code should be put into a Localscript icon.pngLocalScript named ChatScript inside of the Message icon.pngChat service.

-- 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