if year==2007 then script.Parent.ClickToChat.TextColor3=Color3.new(0,0,0)script.Parent.ChatBar.BackgroundColor3=Color3.new(1.0,1.0,1.0)end local Q={ChatColors={BrickColor.new("\066\114\105\103\104\116 \114\101\100"),BrickColor.new("\066\114\105\103\104\116 \098\108\117\101"),BrickColor.new("\069\097\114\116\104 \103\114\101\101\110"),BrickColor.new("\066\114\105\103\104\116 \118\105\111\108\101\116"),BrickColor.new("\066\114\105\103\104\116 \111\114\097\110\103\101");BrickColor.new("\066\114\105\103\104\116 \121\101\108\108\111\119"),BrickColor.new("\076\105\103\104\116 \114\101\100\100\105\115\104 \118\105\111\108\101\116");BrickColor.new("\066\114\105\099\107 \121\101\108\108\111\119")};Gui=nil;Frame=nil,RenderFrame=nil,TapToChatLabel=nil;ClickToChatButton=nil,Templates=nil,EventListener=nil;MessageQueue={};Configuration={FontSize=Enum.FontSize.Size12,NumFontSize=12;HistoryLength=20,Size=UDim2.new(.38,0,.2,0),MessageColor=Color3.new(1,1,1);AdminMessageColor=Color3.new(1,.84313725490196,0);XScale=.025;LifeTime=45,Position=UDim2.new(0,2,.05,0),DefaultTweenSpeed=.15};CachedSpaceStrings_List={},Messages_List={};MessageThread=nil;TempSpaceLabel=nil}function GetNameValue(Q)local R=0 for Y=1,#Q,1 do local n=string.byte(string.sub(Q,Y,Y))local x=(#Q-Y)+1 if#Q%2==1 then x=x-1 end if x%4>=2 then n=-n end R=R+n end return R%8 end function Q.ComputeChatColor(R,Q)return R.ChatColors[GetNameValue(Q)+1].Color end function Q.UpdateQueue(Y,Q,R)for n=#Y.MessageQueue,1,-1 do if Y.MessageQueue[n]then for x,D in pairs(Y.MessageQueue[n])do if D and(type(D)~="\116\097\098\108\101"and type(D)~="\110\117\109\098\101\114")then if D:IsA("\084\101\120\116\076\097\098\101\108")or D:IsA("\084\101\120\116\066\117\116\116\111\110")then if R then D.Position=D.Position-UDim2.new(0,0,R,0)else if Q==Y.MessageQueue[n]then D.Position=UDim2.new(Y.Configuration.XScale,0,D.Position.Y.Scale-Q.Message.Size.Y.Scale,0)else D.Position=UDim2.new(Y.Configuration.XScale,0,D.Position.Y.Scale-Q.Message.Size.Y.Scale,0)end if D.Position.Y.Scale<-0.01 then D.Visible=false D:Destroy()end end end end end end end end function Q.ComputeSpaceString(R,Q)local Y=" "if not R.TempSpaceLabel then R.TempSpaceLabel=R.Templates.SpaceButton R.TempSpaceLabel.Size=UDim2.new(0,Q.AbsoluteSize.X,0,Q.AbsoluteSize.Y)end R.TempSpaceLabel.Text=Y while R.TempSpaceLabel.TextBounds.X<Q.TextBounds.X do Y=Y.." "R.TempSpaceLabel.Text=Y end Y=Y.." "R.CachedSpaceStrings_List[Q.Text]=Y R.TempSpaceLabel.Text=""return Y end function Q.UpdateChat(n,R,Y)local x={Player=R;Message=Y}if coroutine.status(Q.MessageThread)=="\100\101\097\100"then table.insert(Q.Messages_List,x)Q.MessageThread=coroutine.create(function()for R=1,#Q.Messages_List,1 do local Y=Q.Messages_List[R]Q:CreateMessage(Y.Player,Y.Message)end Q.Messages_List={}end)coroutine.resume(Q.MessageThread)else table.insert(Q.Messages_List,x)end end function Q.CreateMessage(n,R,Y)local x=R~=nil and R.Name or"\071\065\077\069"Y=Y:gsub("\094\037\115\042\040\046-\041\037\115\042\036","\037\049")n.MessageQueue[#n.MessageQueue]=#n.MessageQueue>n.Configuration.HistoryLength and nil or n.MessageQueue[#n.MessageQueue]local D=n.Templates.pLabel:clone()D.Name=x D.Text=x.."\059"D.Parent=n.RenderFrame D.TextColor3=R.Neutral and Q:ComputeChatColor(x)or R.TeamColor.Color local s=n.CachedSpaceStrings_List[x]or Q:ComputeSpaceString(D)local V=n.Templates.mLabel:clone()V.Name=x.." - \109\101\115\115\097\103\101"V.TextColor3=Q.Configuration.MessageColor V.Text=s..Y V.Parent=n.RenderFrame local W=V.TextBounds.Y V.Size=UDim2.new(1,0,W/n.RenderFrame.AbsoluteSize.Y,0)D.Size=V.Size local N=n.RenderFrame.AbsoluteSize.Y local Z=V.TextBounds.Y local d={}d.Player=D d.Message=V d.SpawnTime=tick()table.insert(n.MessageQueue,1,d)Q:UpdateQueue(d)end function Q.CreateChatBar(Q)Q.ClickToChatButton=Q.Gui:WaitForChild("\067\108\105\099\107\084\111\067\104\097\116")Q.ChatBar=Q.Gui:WaitForChild("\067\104\097\116\066\097\114")local R=game.Players.LocalPlayer:GetMouse()R.KeyDown:connect(function(R)if R:byte()==47 or R=="\047"then wait(1e-08)Q.ClickToChatButton.Visible=false if year>2007 then Q.ChatBar.BackgroundColor3=Color3.new(.0,.0,.0)end Q.ChatBar:CaptureFocus()end end)Q.ClickToChatButton.MouseButton1Click:connect(function()Q.ClickToChatButton.Visible=false if year>2007 then Q.ChatBar.BackgroundColor3=Color3.new(.0,.0,.0)end Q.ChatBar:CaptureFocus()end)end function Q.PlayerChat(R,Q)local Y=Instance.new("\083\116\114\105\110\103\086\097\108\117\101")Y.Name="\078\101\119\077\101\115\115\097\103\101"Y.Value=Q Y.Parent=game.Players.LocalPlayer;(game:GetService("\068\101\098\114\105\115")):AddItem(Y,2)end function Q.CreateGui(R)R.Gui=script.Parent R.Frame=R.Gui:WaitForChild("\067\104\097\116\070\114\097\109\101")R.RenderFrame=R.Frame:WaitForChild("\067\104\097\116\082\101\110\100\101\114\070\114\097\109\101")R.Templates=R.Gui:WaitForChild("\084\101\109\112\108\097\116\101\115")Q:CreateChatBar()R.ChatBar.FocusLost:connect(function(Y)if year>2007 then R.ChatBar.BackgroundColor3=Color3.new(.0,.0,.0)end if Y and R.ChatBar.Text~=""then local Y=R.ChatBar.Text if string.sub(R.ChatBar.Text,1,1)=="\037"then Y="\040\084\069\065\077\041 "..string.sub(Y,2,#Y)end Q:PlayerChat(Y)if R.ClickToChatButton then R.ClickToChatButton.Visible=true end R.ChatBar.Text=""R.ClickToChatButton.Visible=true end end)end function Q.TrackPlayerChats(R)local function Y(R)R.ChildAdded:connect(function(Y)if Y:IsA("\083\116\114\105\110\103\086\097\108\117\101")and Y.Name=="\078\101\119\077\101\115\115\097\103\101"then if game.Players.LocalPlayer.Neutral or R.TeamColor==game.Players.LocalPlayer.TeamColor then Q:UpdateChat(R,Y.Value)end end end)end for Q,R in pairs(game.Players:GetPlayers())do Y(R)end game.Players.PlayerAdded:connect(Y)end function Q.CullThread(Q)Spawn(function()while true do if#Q.MessageQueue>0 then for R,Y in pairs(Q.MessageQueue)do if Y.SpawnTime and(Y.Player and(Y.Message and tick()-Y.SpawnTime>Q.Configuration.LifeTime))then Y.Player.Visible=false Y.Message.Visible=false end end end wait(5)end end)end function Q.Initialize(R)Q:CreateGui()Q:TrackPlayerChats()R.MessageThread=coroutine.create(function() end)coroutine.resume(R.MessageThread)Q:CullThread()end Q:Initialize()


if year == 2007 then
	script.Parent.ClickToChat.TextColor3 = Color3.new(0, 0, 0)
	script.Parent.ChatBar.BackgroundColor3 = Color3.new(255/255, 255/255, 255/255)
end

local Chat = { 
	ChatColors = {
		BrickColor.new("Bright red"),
		BrickColor.new("Bright blue"),
		BrickColor.new("Earth green"),
		BrickColor.new("Bright violet"),
		BrickColor.new("Bright orange"),
		BrickColor.new("Bright yellow"),
		BrickColor.new("Light reddish violet"),
		BrickColor.new("Brick yellow"),
	};

	Gui = nil,
	Frame = nil,
	RenderFrame = nil,
	TapToChatLabel = nil,
	ClickToChatButton = nil,
	Templates = nil,
	EventListener = nil,
	MessageQueue = {},
	
	Configuration = {								
		FontSize = Enum.FontSize.Size12,	
		NumFontSize = 12,
		HistoryLength = 20,
		Size = UDim2.new(0.38, 0, 0.20, 0),
		MessageColor = Color3.new(1 , 1, 1),
		AdminMessageColor = Color3.new(1, 215/255, 0),
		XScale = 0.025,
		LifeTime = 45,
		Position = UDim2.new(0, 2, 0.05, 0),
		DefaultTweenSpeed = 0.15,							
	};
	
	CachedSpaceStrings_List = {},
	Messages_List = {},
	MessageThread = nil,
	TempSpaceLabel = nil,
}

function GetNameValue(pName)
	local value = 0
	for index = 1, #pName do 
		local cValue = string.byte(string.sub(pName, index, index))
		local reverseIndex = #pName - index + 1
		if #pName%2 == 1 then 
			reverseIndex = reverseIndex - 1			
		end
		if reverseIndex%4 >= 2 then 
			cValue = -cValue 			
		end 
		value = value + cValue 
	end 
	return value%8
end 

function Chat:ComputeChatColor(pName)
	return self.ChatColors[GetNameValue(pName) + 1].Color
end 

function Chat:UpdateQueue(field, diff)	 				
	for i = #self.MessageQueue, 1, -1 do 			
		if self.MessageQueue[i] then 						
			for _, label in pairs(self.MessageQueue[i]) do 						
				if label and type(label) ~= "table" and type(label) ~= "number" then					
					if label:IsA("TextLabel") or label:IsA("TextButton") then 	
						if diff then 
							label.Position = label.Position - UDim2.new(0, 0, diff, 0) 
						else											
							if field == self.MessageQueue[i] then 						
								label.Position = UDim2.new(self.Configuration.XScale, 0, label.Position.Y.Scale - field["Message"].Size.Y.Scale , 0)
							else 							
								label.Position = UDim2.new(self.Configuration.XScale, 0, label.Position.Y.Scale - field["Message"].Size.Y.Scale, 0)							
							end  
							if label.Position.Y.Scale < -0.01 then 							
								label.Visible = false 						
								label:Destroy() 
							end 
						end 
					end 
				end 						
			end 
		end 
	end	
end 

function Chat:ComputeSpaceString(pLabel)
	local nString = " "
	if not self.TempSpaceLabel then 
		self.TempSpaceLabel = self.Templates.SpaceButton
		self.TempSpaceLabel.Size = UDim2.new(0, pLabel.AbsoluteSize.X, 0, pLabel.AbsoluteSize.Y); 
	end
	self.TempSpaceLabel.Text = nString
	while self.TempSpaceLabel.TextBounds.X < pLabel.TextBounds.X do 
		nString = nString .. " "
		self.TempSpaceLabel.Text = nString 				
	end 
	nString = nString .. " "
	self.CachedSpaceStrings_List[pLabel.Text] = nString 
	self.TempSpaceLabel.Text = ""
	return nString	
end


function Chat:UpdateChat(cPlayer, message)
	local messageField = {["Player"] = cPlayer,["Message"] = message}	
	if coroutine.status(Chat.MessageThread) == "dead" then 				
		table.insert(Chat.Messages_List, messageField)				
		Chat.MessageThread = coroutine.create(function ()
			for i = 1, #Chat.Messages_List do 	
				local field = Chat.Messages_List[i]																														
				Chat:CreateMessage(field["Player"], field["Message"]) 						
			end 
			Chat.Messages_List = {}									
		end)
		coroutine.resume(Chat.MessageThread)
	else 
		table.insert(Chat.Messages_List, messageField)
	end 
end 

function Chat:CreateMessage(cPlayer, message)		
	local pName = cPlayer ~= nil and cPlayer.Name or "GAME"	
	message = message:gsub("^%s*(.-)%s*$", "%1")		
	self.MessageQueue[#self.MessageQueue] = (#self.MessageQueue > self.Configuration.HistoryLength) and nil or self.MessageQueue[#self.MessageQueue]
	local pLabel = self.Templates.pLabel:clone()
	pLabel.Name = pName;
	pLabel.Text = pName .. ";";
	pLabel.Parent = self.RenderFrame;			
	pLabel.TextColor3 = (cPlayer.Neutral) and Chat:ComputeChatColor(pName) or cPlayer.TeamColor.Color 
	local nString = self.CachedSpaceStrings_List[pName] or Chat:ComputeSpaceString(pLabel)
	local mLabel = self.Templates.mLabel:clone()
	mLabel.Name = pName .. " - message";					
	mLabel.TextColor3 = Chat.Configuration.MessageColor;					
	mLabel.Text = nString .. message;
	mLabel.Parent = self.RenderFrame;	
	local heightField = mLabel.TextBounds.Y	
	mLabel.Size = UDim2.new(1, 0, heightField/self.RenderFrame.AbsoluteSize.Y, 0)	
	pLabel.Size = mLabel.Size
	local yPixels = self.RenderFrame.AbsoluteSize.Y
	local yFieldSize = mLabel.TextBounds.Y
	local queueField = {}	
	queueField["Player"] = pLabel 
	queueField["Message"] = mLabel 
	queueField["SpawnTime"] = tick()
	table.insert(self.MessageQueue, 1, queueField)		
	Chat:UpdateQueue(queueField)
end

function Chat:CreateChatBar()	
	self.ClickToChatButton = self.Gui:WaitForChild("ClickToChat")
	self.ChatBar = self.Gui:WaitForChild("ChatBar")
	local mouse = game.Players.LocalPlayer:GetMouse()
	mouse.KeyDown:connect(function (key)
		if key:byte() == 47 or key == "/" then
			wait(0.00000001)
			self.ClickToChatButton.Visible = false
			if year > 2007 then
				self.ChatBar.BackgroundColor3 = Color3.new(0/255, 0/255, 0/255)
			end
			self.ChatBar:CaptureFocus()
		end
	end)
	self.ClickToChatButton.MouseButton1Click:connect(function ()
		self.ClickToChatButton.Visible = false
		if year > 2007 then
			self.ChatBar.BackgroundColor3 = Color3.new(0/255, 0/255, 0/255)
		end
		self.ChatBar:CaptureFocus()
	end)	
end

function Chat:PlayerChat(message)
	local m = Instance.new("StringValue")
	m.Name = "NewMessage"
	m.Value = message
	m.Parent = game.Players.LocalPlayer
	game:GetService("Debris"):AddItem(m, 2)
end

function Chat:CreateGui()
	self.Gui = script.Parent
	self.Frame = self.Gui:WaitForChild("ChatFrame")
	self.RenderFrame = self.Frame:WaitForChild("ChatRenderFrame")
	self.Templates = self.Gui:WaitForChild("Templates")	
	Chat:CreateChatBar()
	self.ChatBar.FocusLost:connect(function(enterPressed)
		if year > 2007 then
			self.ChatBar.BackgroundColor3 = Color3.new(0/255, 0/255, 0/255)
		end
		if enterPressed and self.ChatBar.Text ~= "" then 
			local cText = self.ChatBar.Text
			if string.sub(self.ChatBar.Text, 1, 1)  == "%" then 
				cText = "(TEAM) " .. string.sub(cText, 2, #cText)
			end
			Chat:PlayerChat(cText)											
			if self.ClickToChatButton then 
				self.ClickToChatButton.Visible = true 
			end 
			self.ChatBar.Text = ""	
			self.ClickToChatButton.Visible = true							
		end	
	end)	
end

function Chat:TrackPlayerChats()
	local function chatRegister(p)
		p.ChildAdded:connect(function (obj)
			if obj:IsA("StringValue") and obj.Name == "NewMessage" then
				if game.Players.LocalPlayer.Neutral or p.TeamColor == game.Players.LocalPlayer.TeamColor then
					Chat:UpdateChat(p, obj.Value)
				end
			end
		end)
	end
	for _,v in pairs(game.Players:GetPlayers()) do
		chatRegister(v)
	end
	game.Players.PlayerAdded:connect(chatRegister)
end

function Chat:CullThread()
	Spawn(function ()
		while true do 
			if #self.MessageQueue > 0 then 
				for _, field in pairs(self.MessageQueue) do 				
					if field["SpawnTime"] and field["Player"] and field["Message"] and tick() - field["SpawnTime"] > self.Configuration.LifeTime then 
						field["Player"].Visible = false 
						field["Message"].Visible = false 
					end 
				end 
			end 
			wait(5)
		end
	end)
end

function Chat:Initialize()			
	Chat:CreateGui()
	Chat:TrackPlayerChats()
	self.MessageThread = coroutine.create(function () end)
						 coroutine.resume(self.MessageThread)
	Chat:CullThread()
end

Chat:Initialize()
