Problem with disabling/enabling chat for specific UI

Iā€™m trying to make the ui disable chat when opening, and reenable it after closing the UI. Issue is, It keeps giving me this error.
image

local player = game.Players.LocalPlayer
local LoadoutScreen = player.PlayerGui.Weapons
local Exit = script.Parent
local cas = game:GetService("ContextActionService")

function ExitClicked()
	LoadoutScreen.Enabled = false
	cas:UnbindAction("DisableControls")
	local PlayerGui = game.Players.LocalPlayer.PlayerGui
	PlayerGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
end

Exit.Activated:connect(ExitClicked)

(I only gave the exit UI because both scripts give the same error for the same reasons, but the exit script is cleaner.)

1 Like

You do it on startergui instead

game.StarterGui:SetCoreEnabled(Enum.CoreGuiType.Chat, true)

1 Like

As mentioned above, both SetCoreGuiEnabled and SetCore are functions of StarterGui not the PlayerGui.

1 Like
local player = game.Players.LocalPlayer
local LoadoutScreen = player.PlayerGui.Weapons
local Exit = script.Parent
local cas = game:GetService("ContextActionService")
local sg = game:GetService("StarterGui")

function ExitClicked()
	LoadoutScreen.Enabled = false
	cas:UnbindAction("DisableControls")
	sg:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
end

Exit.Activated:connect(ExitClicked)
1 Like

Use this:

local player = game.Players.LocalPlayer
local LoadoutScreen = player.PlayerGui.Weapons
local Exit = script.Parent
local cas = game:GetService("ContextActionService")
local StarterGui = game:GetService("StarterGui")

function ExitClicked()
	LoadoutScreen.Enabled = false
	cas:UnbindAction("DisableControls")
	local PlayerGui = game.Players.LocalPlayer.PlayerGui
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
end

Exit.Activated:connect(ExitClicked)
1 Like
local sg = game:GetService("StarterGui")
local cas = game:GetService("ContextActionService")

local players = game:GetService("Players")
local player = players.LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local loadout = playergui:WaitForChild("Weapons")

local exit = script.Parent

local function ExitClicked()
	loadout.Enabled = false
	cas:UnbindAction("DisableControls")
	sg:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
end

exit.Activated:Connect(ExitClicked)

What has already been suggested but define the function locally and use the event instance method for creating connections between events and callbacks ā€œ:Connect()ā€ not ā€œ:connect()ā€ as the latter is deprecated.

1 Like