local e=5 local l=game.Players.LocalPlayer local Z=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local j=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local v="\084\111 \099\104\097\116 \110\097\118\105\103\097\116\101 \104\101\114\101 \097\110\100 \099\108\105\099\107"local D=script.Parent.TypeArea.Text local q=1 local h=false local c=0 function tweenToVisible()local e={BackgroundTransparency=.6}local l={TextTransparency=.3};(Z:Create(script.Parent,TweenInfo.new(.35,Enum.EasingStyle.Linear),e)):Play();(Z:Create(script.Parent.WhiteArea,TweenInfo.new(.5,Enum.EasingStyle.Linear),e)):Play();(Z:Create(script.Parent.TypeArea,TweenInfo.new(.5,Enum.EasingStyle.Linear),l)):Play()end function tweenToInvisible()local e={BackgroundTransparency=.8}local l={TextTransparency=.65};(Z:Create(script.Parent,TweenInfo.new(.35,Enum.EasingStyle.Linear),e)):Play();(Z:Create(script.Parent.WhiteArea,TweenInfo.new(.5,Enum.EasingStyle.Linear),e)):Play();(Z:Create(script.Parent.TypeArea,TweenInfo.new(.5,Enum.EasingStyle.Linear),l)):Play()end function tweenToTripleSize()h=true local e={Size=UDim2.new(.5,-230,0,72)}local l=Z:Create(script.Parent,TweenInfo.new(.05,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),e)l.Completed:connect(function()h=false end)l:Play()end function tweenToDoubleSize()h=true local e={Size=UDim2.new(.5,-230,0,56)}local l=Z:Create(script.Parent,TweenInfo.new(.05,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),e)l.Completed:connect(function()h=false end)l:Play()end function tweenToNormalSize()h=true local e={Size=UDim2.new(.5,-230,0,40)}local l=Z:Create(script.Parent,TweenInfo.new(.05,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),e)l.Completed:connect(function()h=false end)l:Play()end script.Parent.TypeArea.Focused:connect(function()if script.Parent.TypeArea.Text==v then script.Parent.TypeArea.Text=""end tweenToVisible()end)script.Parent.TypeArea.FocusLost:connect(function(Z)if Z then local Z=script.Parent.TypeArea.Text for e=1,string.len(script.Parent.TypeArea.Text),1 do if string.sub(script.Parent.TypeArea.Text,e,e)==" "and e<string.len(script.Parent.TypeArea.Text)then Z=string.sub(script.Parent.TypeArea.Text,e+1,string.len(script.Parent.TypeArea.Text))else if string.sub(script.Parent.TypeArea.Text,e,e)==" "then Z=""end break end end if Z~=""then local e=Z for l=string.len(e),1,-1 do if string.sub(e,l,l)==" "and l>1 then Z=string.sub(e,1,l-1)else if string.sub(e,l,l)==" "then Z=""end break end end end if Z~=""and c<=e then game.ReplicatedStorage.Interactions.Server.SendChatMessage:FireServer(Z)c=c+2 elseif Z~=""and c>e then l.PlayerGui.MainGui.Chat.ShowChatMessage:Fire(nil,"\089\111\117 \097\114\101 \099\104\097\116\116\105\110\103 \116\111\111 \113\117\105\099\107\108\121\046 \089\111\117 \099\097\110 \099\104\097\116 \097\103\097\105\110 \105\110 "..(c-e.." \115\101\099\111\110\100\115\046"))end script.Parent.TypeArea.Text=v else if script.Parent.TypeArea.Text==""then script.Parent.TypeArea.Text=v end end tweenToInvisible()end);(script.Parent.TypeArea:GetPropertyChangedSignal("\084\101\120\116")):connect(function()if not h then if not script.Parent.TypeArea.TextFits and q==1 then tweenToDoubleSize()q=2 elseif not script.Parent.TypeArea.TextFits and q==2 then tweenToTripleSize()q=3 elseif not script.Parent.TypeArea.TextFits and q==3 then script.Parent.TypeArea.Text=D elseif q>2 and script.Parent.TypeArea.TextBounds.Y==32 then tweenToDoubleSize()q=2 elseif q>1 and script.Parent.TypeArea.TextBounds.Y==16 then tweenToNormalSize()q=1 end end D=script.Parent.TypeArea.Text end)

local MAX_SPAM_SCORE = 5

local plr = game.Players.LocalPlayer
local tweenService = game:GetService("TweenService")
local inputService = game:GetService("UserInputService")

local defaultMsg = "To chat navigate here and click"
local previousText = script.Parent.TypeArea.Text
local size = 1
local tweenInProgress = false
local spamScore = 0

function tweenToVisible()
	
	-- Tween transparencies
	local goal1 = { BackgroundTransparency = 0.6 }
	local goal2 = { TextTransparency = 0.3 }
	tweenService:Create(script.Parent, TweenInfo.new(0.35, Enum.EasingStyle.Linear), goal1):Play()
	tweenService:Create(script.Parent.WhiteArea, TweenInfo.new(0.5, Enum.EasingStyle.Linear), goal1):Play()
	tweenService:Create(script.Parent.TypeArea, TweenInfo.new(0.5, Enum.EasingStyle.Linear), goal2):Play()
	
end

function tweenToInvisible()
	
	-- Tween transparencies
	local goal1 = { BackgroundTransparency = 0.8 }
	local goal2 = { TextTransparency = 0.65 }
	tweenService:Create(script.Parent, TweenInfo.new(0.35, Enum.EasingStyle.Linear), goal1):Play()
	tweenService:Create(script.Parent.WhiteArea, TweenInfo.new(0.5, Enum.EasingStyle.Linear), goal1):Play()
	tweenService:Create(script.Parent.TypeArea, TweenInfo.new(0.5, Enum.EasingStyle.Linear), goal2):Play()
	
end

function tweenToTripleSize()
	
	-- Tween size
	tweenInProgress = true
	local goal = { Size = UDim2.new(0.5, -230 , 0, 72) }
	local tween = tweenService:Create(script.Parent, TweenInfo.new(0.05, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), goal)
	tween.Completed:connect(function()
		tweenInProgress = false
	end)
	tween:Play()
	
end

function tweenToDoubleSize()
	
	-- Tween size
	tweenInProgress = true
	local goal = { Size = UDim2.new(0.5, -230 , 0, 56) }
	local tween = tweenService:Create(script.Parent, TweenInfo.new(0.05, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), goal)
	tween.Completed:connect(function()
		tweenInProgress = false
	end)
	tween:Play()
	
end

function tweenToNormalSize()
	
	-- Tween size
	tweenInProgress = true
	local goal = { Size = UDim2.new(0.5, -230 , 0, 40) }
	local tween = tweenService:Create(script.Parent, TweenInfo.new(0.05, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), goal)
	tween.Completed:connect(function()
		tweenInProgress = false
	end)
	tween:Play()
	
end

script.Parent.TypeArea.Focused:connect(function()
		
	-- Reset text if default
	if script.Parent.TypeArea.Text == defaultMsg then
		script.Parent.TypeArea.Text = ""
	end
	
	-- Make more visible
	tweenToVisible()
	
end)

script.Parent.TypeArea.FocusLost:connect(function(enterPressed)
	
	-- Check if enter was pressed
	if enterPressed then
		
		-- Clear spaces at beginning
		local msg = script.Parent.TypeArea.Text
		for i=1, string.len(script.Parent.TypeArea.Text) do
			if string.sub(script.Parent.TypeArea.Text, i, i) == ' ' and i < string.len(script.Parent.TypeArea.Text) then
				msg = string.sub(script.Parent.TypeArea.Text, i + 1, string.len(script.Parent.TypeArea.Text))
			else
				if string.sub(script.Parent.TypeArea.Text, i, i) == ' ' then
					msg = ""
				end
				break
			end
		end
		
		-- Clear spaces at end
		if msg ~= "" then
			local prevMsg = msg
			for i=string.len(prevMsg), 1, -1 do
				if string.sub(prevMsg, i, i) == ' ' and i > 1 then
					msg = string.sub(prevMsg, 1, i - 1)
				else
					if string.sub(prevMsg, i, i) == ' ' then
						msg = ""
					end
					break
				end
			end
		end
		
		-- Send message if not blank
		if msg ~= "" and spamScore <= MAX_SPAM_SCORE then
			game.ReplicatedStorage.Interactions.Server.SendChatMessage:FireServer(msg)
			spamScore = spamScore + 2
		elseif msg ~= "" and spamScore > MAX_SPAM_SCORE then
			plr.PlayerGui.MainGui.Chat.ShowChatMessage:Fire(nil, "You are chatting too quickly. You can chat again in " .. spamScore - MAX_SPAM_SCORE .. " seconds.")
		end
		
		-- Clear set text to default text
		script.Parent.TypeArea.Text = defaultMsg
		
	else
		
		-- Set to default if blank
		if script.Parent.TypeArea.Text == "" then
			script.Parent.TypeArea.Text = defaultMsg
		end
		
	end
	
	-- Make less visible
	tweenToInvisible()
	
end)

script.Parent.TypeArea:GetPropertyChangedSignal("Text"):connect(function()
	
	-- Check if went out of bounds
	if not tweenInProgress then
		if not script.Parent.TypeArea.TextFits and size == 1 then
			tweenToDoubleSize()
			size = 2
		elseif not script.Parent.TypeArea.TextFits and size == 2 then
			tweenToTripleSize()
			size = 3
		elseif not script.Parent.TypeArea.TextFits and size == 3 then
			script.Parent.TypeArea.Text = previousText
		elseif size > 2 and script.Parent.TypeArea.TextBounds.Y == 32 then
			tweenToDoubleSize()
			size = 2
		elseif size > 1 and script.Parent.TypeArea.TextBounds.Y == 16 then
			tweenToNormalSize()
			size = 1
		end
	end
	
	-- Set previous text
	previousText = script.Parent.TypeArea.Text
	
end)
