local x=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local g=game:GetService("\082\117\110\083\101\114\118\105\099\101")local u=game:GetService("\080\108\097\121\101\114\115")local e=u.LocalPlayer while not e do u.ChildAdded:wait()e=u.LocalPlayer end local Y=true local v=6 if ChatSettings.ScreenGuiDisplayOrder~=nil then v=ChatSettings.ScreenGuiDisplayOrder end local R=e:WaitForChild("\080\108\097\121\101\114\071\117\105")local G=Instance.new("\083\099\114\101\101\110\071\117\105")G.Name="\067\104\097\116"G.ResetOnSpawn=false G.DisplayOrder=v G.Parent=R local E=false local r=script local j=require(r:WaitForChild("\067\104\097\116\087\105\110\100\111\119"))local V=require(r:WaitForChild("\067\104\097\116\066\097\114"))local W=require(r:WaitForChild("\067\104\097\110\110\101\108\115\066\097\114"))local U=require(r:WaitForChild("\077\101\115\115\097\103\101\076\097\098\101\108\067\114\101\097\116\111\114"))local l=require(r:WaitForChild("\077\101\115\115\097\103\101\076\111\103\068\105\115\112\108\097\121"))local o=require(r:WaitForChild("\067\104\097\116\067\104\097\110\110\101\108"))local s=require(r:WaitForChild("\067\111\109\109\097\110\100\080\114\111\099\101\115\115\111\114"))local d=j.new()local Z=W.new()local S=l.new()local J=s.new()local T=V.new(J,d)d:CreateGuiObjects(G)d:RegisterChatBar(T)d:RegisterChannelsBar(Z)d:RegisterMessageLogDisplay(S)MessageCreatorUtil:RegisterChatWindow(d)local h=require(r:WaitForChild("\077\101\115\115\097\103\101\083\101\110\100\101\114"))h:RegisterSayMessageFunction(EventFolder.SayMessageRequest)if x.TouchEnabled then T:SetTextLabelText("\084\097\112 \104\101\114\101 \116\111 \099\104\097\116")else T:SetTextLabelText("\084\111 \099\104\097\116 \099\108\105\099\107 \104\101\114\101 \111\114 \112\114\101\115\115 \"\047\" \107\101\121")end spawn(function()local x=require(r:WaitForChild("\067\117\114\118\101\085\116\105\108"))local g=ChatSettings.ChatAnimationFPS or 20.0 local u=1.0/g local e=tick()while true do local g=tick()local Y=g-e local v=x:DeltaTimeToTimescale(Y)if v~=0 then d:Update(v)end e=g wait(u)end end)


local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

while not LocalPlayer do
	Players.ChildAdded:wait()
	LocalPlayer = Players.LocalPlayer
end

local canChat = true

local ChatDisplayOrder = 6
if ChatSettings.ScreenGuiDisplayOrder ~= nil then
	ChatDisplayOrder = ChatSettings.ScreenGuiDisplayOrder
end

local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
local GuiParent = Instance.new("ScreenGui")
GuiParent.Name = "Chat"
GuiParent.ResetOnSpawn = false
GuiParent.DisplayOrder = ChatDisplayOrder
GuiParent.Parent = PlayerGui

local DidFirstChannelsLoads = false

local modulesFolder = script

local moduleChatWindow = require(modulesFolder:WaitForChild("ChatWindow"))
local moduleChatBar = require(modulesFolder:WaitForChild("ChatBar"))
local moduleChannelsBar = require(modulesFolder:WaitForChild("ChannelsBar"))
local moduleMessageLabelCreator = require(modulesFolder:WaitForChild("MessageLabelCreator"))
local moduleMessageLogDisplay = require(modulesFolder:WaitForChild("MessageLogDisplay"))
local moduleChatChannel = require(modulesFolder:WaitForChild("ChatChannel"))
local moduleCommandProcessor = require(modulesFolder:WaitForChild("CommandProcessor"))

local ChatWindow = moduleChatWindow.new()
local ChannelsBar = moduleChannelsBar.new()
local MessageLogDisplay = moduleMessageLogDisplay.new()
local CommandProcessor = moduleCommandProcessor.new()
local ChatBar = moduleChatBar.new(CommandProcessor, ChatWindow)

ChatWindow:CreateGuiObjects(GuiParent)

ChatWindow:RegisterChatBar(ChatBar)
ChatWindow:RegisterChannelsBar(ChannelsBar)
ChatWindow:RegisterMessageLogDisplay(MessageLogDisplay)

MessageCreatorUtil:RegisterChatWindow(ChatWindow)

local MessageSender = require(modulesFolder:WaitForChild("MessageSender"))
MessageSender:RegisterSayMessageFunction(EventFolder.SayMessageRequest)



if (UserInputService.TouchEnabled) then
	ChatBar:SetTextLabelText('Tap here to chat')
else
	ChatBar:SetTextLabelText('To chat click here or press "/" key')
end

spawn(function()
	local CurveUtil = require(modulesFolder:WaitForChild("CurveUtil"))
	local animationFps = ChatSettings.ChatAnimationFPS or 20.0

	local updateWaitTime = 1.0 / animationFps
	local lastTick = tick()
	while true do
		local currentTick = tick()
		local tickDelta = currentTick - lastTick
		local dtScale = CurveUtil:DeltaTimeToTimescale(tickDelta)

		if dtScale ~= 0 then
			ChatWindow:Update(dtScale)
		end

		lastTick = currentTick
		wait(updateWaitTime)
	end
end)



