Detect when the chat toggle button is pressed

I am trying to make a custom chat gui using the new TextChatService system.

I’ve noticed that when I disable the chat bar and window, the toggle button at the top of the screen stays there.
image
(Not sure why my Studio has the old UI)

This would be really useful, as I will not need to make my own, however, I am not sure how I can detect when this button is clicked. Does anyone have any ideas as to how I can?

Something like this should work:

local SG = game:GetService("StarterGui")

local event = Instance.new("BindableEvent")

local tries = 10

for _ = 1, tries do
	local success = pcall(SG.SetCore, SG, "CoreGuiChatConnections", {ChatWindow = {ToggleVisibility = event}})
	if success then break end
	task.wait()
end

event.Event:Connect(function()
	print("Chat button pressed")
end)

Thanks mate. Just tested it and it works as you said :+1:

1 Like