local B=game:GetService("\080\108\097\121\101\114\115")local Y=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local J=game:GetService("\067\111\110\116\101\120\116\065\099\116\105\111\110\083\101\114\118\105\099\101")local U=require(script.Parent.bind)local y=require(script.Parent.Comment)local S=require(script.Parent.AccessList)local A=require(script.Parent.RenderstepTracker)local Z=require(script.Parent.AddCommentHud)if not S.clientQueryHasAccess()then return end local z=Instance.new("\083\099\114\101\101\110\071\117\105")z.Name="\067\111\109\109\101\110\116\083\099\114\101\101\110\071\117\105"z.Parent=B.LocalPlayer.PlayerGui z.ResetOnSpawn=false local K,v local function a()K()K=nil A.uninstall()v:Destroy()end local function e()A.install()K=U("\067\111\109\109\101\110\116",y)v=Z.new(a)end J:BindAction("\084\111\103\103\108\101\067\111\109\109\101\110\116\086\105\115\105\098\105\108\105\116\121",function()if K then a()else e()end end,false,Enum.KeyCode.Tab)e()
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")

local bind = require(script.Parent.bind)
local Comment = require(script.Parent.Comment)
local AccessList = require(script.Parent.AccessList)
local RenderstepTracker = require(script.Parent.RenderstepTracker)
local AddCommentHud = require(script.Parent.AddCommentHud)

-- Don't show comments or let people comment if they don't have access
if not AccessList.clientQueryHasAccess() then
	return
end

-- Make CommentScreenGui under PlayerGui
local commentScreenGui = Instance.new("ScreenGui")
commentScreenGui.Name = "CommentScreenGui"
commentScreenGui.Parent = Players.LocalPlayer.PlayerGui
commentScreenGui.ResetOnSpawn = false

local unbind, addCommentHud;

local function teardown()
	unbind()
	unbind = nil
	RenderstepTracker.uninstall()
	addCommentHud:Destroy()
end

local function setup()
	-- Track rendersteps
	RenderstepTracker.install()

	-- Bind comments
	unbind = bind("Comment", Comment)

	-- Add the comment HUD
	addCommentHud = AddCommentHud.new(teardown)
end

-- Toggle visibility when the tab key is pressed
ContextActionService:BindAction("ToggleCommentVisibility", function()
	if unbind then
		teardown()
	else
		setup()
	end
end, false, Enum.KeyCode.Tab)

setup()
