local s=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local d=game:GetService("\082\117\110\083\101\114\118\105\099\101")local h=game:GetService("\080\108\097\121\101\114\115")local F=h.LocalPlayer while not F do h.ChildAdded:wait()F=h.LocalPlayer end local o=true local A=6 if ChatSettings.ScreenGuiDisplayOrder~=nil then A=ChatSettings.ScreenGuiDisplayOrder end local M=F:WaitForChild("\080\108\097\121\101\114\071\117\105")local k=Instance.new("\083\099\114\101\101\110\071\117\105")k.Name="\067\104\097\116"k.ResetOnSpawn=false k.DisplayOrder=A k.Parent=M local b=false local i=script local V=require(i:WaitForChild("\067\104\097\116\087\105\110\100\111\119"))local m=require(i:WaitForChild("\067\104\097\116\066\097\114"))local t=require(i:WaitForChild("\067\104\097\110\110\101\108\115\066\097\114"))local c=require(i:WaitForChild("\077\101\115\115\097\103\101\076\097\098\101\108\067\114\101\097\116\111\114"))local x=require(i:WaitForChild("\077\101\115\115\097\103\101\076\111\103\068\105\115\112\108\097\121"))local X=require(i:WaitForChild("\067\104\097\116\067\104\097\110\110\101\108"))local f=require(i:WaitForChild("\067\111\109\109\097\110\100\080\114\111\099\101\115\115\111\114"))local u=V.new()local q=t.new()local I=x.new()local p=f.new()local a=m.new(p,u)u:CreateGuiObjects(k)u:RegisterChatBar(a)u:RegisterChannelsBar(q)u:RegisterMessageLogDisplay(I)MessageCreatorUtil:RegisterChatWindow(u)local L=require(i:WaitForChild("\077\101\115\115\097\103\101\083\101\110\100\101\114"))L:RegisterSayMessageFunction(EventFolder.SayMessageRequest)if s.TouchEnabled then a:SetTextLabelText("\084\097\112 \104\101\114\101 \116\111 \099\104\097\116")else a: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 s=require(i:WaitForChild("\067\117\114\118\101\085\116\105\108"))local d=ChatSettings.ChatAnimationFPS or 20.0 local h=1.0/d local F=tick()while true do local d=tick()local o=d-F local A=s:DeltaTimeToTimescale(o)if A~=0 then u:Update(A)end F=d wait(h)end end)
--// Rest of code after waiting for correct events.

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)
