local b=5 local W=game.Players.LocalPlayer local s=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local D="\084\097\112 \104\101\114\101 \116\111 \099\104\097\116"local j=script.Parent.TypeArea.Text local m=1 local K=false local k=0 function tweenToTripleSize()K=true local b={Size=UDim2.new(1,-365,0,60)}local W=s:Create(script.Parent,TweenInfo.new(.05,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),b)W.Completed:connect(function()K=false end)W:Play()end function tweenToDoubleSize()K=true local b={Size=UDim2.new(1,-365,0,48)}local W=s:Create(script.Parent,TweenInfo.new(.05,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),b)W.Completed:connect(function()K=false end)W:Play()end function tweenToNormalSize()K=true local b={Size=UDim2.new(1,-365,0,36)}local W=s:Create(script.Parent,TweenInfo.new(.05,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),b)W.Completed:connect(function()K=false end)W:Play()end script.Parent.TypeArea.Focused:connect(function()if script.Parent.TypeArea.Text==D then script.Parent.TypeArea.Text=""end end)script.Parent.TypeArea.FocusLost:connect(function(s)if s then local s=script.Parent.TypeArea.Text for b=1,string.len(script.Parent.TypeArea.Text),1 do if string.sub(script.Parent.TypeArea.Text,b,b)==" "and b<string.len(script.Parent.TypeArea.Text)then s=string.sub(script.Parent.TypeArea.Text,b+1,string.len(script.Parent.TypeArea.Text))else if string.sub(script.Parent.TypeArea.Text,b,b)==" "then s=""end break end end if s~=""then local b=s for W=string.len(b),1,-1 do if string.sub(b,W,W)==" "and W>1 then s=string.sub(b,1,W-1)else if string.sub(b,W,W)==" "then s=""end break end end end if s~=""and k<=b then game.ReplicatedStorage.Interactions.Server.SendChatMessage:FireServer(s)k=k+2 elseif s~=""and k>b then W.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 "..(k-b.." \115\101\099\111\110\100\115\046"))end script.Parent.TypeArea.Text=D else if script.Parent.TypeArea.Text==""then script.Parent.TypeArea.Text=D end end end);(script.Parent.TypeArea:GetPropertyChangedSignal("\084\101\120\116")):connect(function()if not K then if not script.Parent.TypeArea.TextFits and m==1 then tweenToDoubleSize()m=2 elseif not script.Parent.TypeArea.TextFits and m==2 then tweenToTripleSize()m=3 elseif not script.Parent.TypeArea.TextFits and m==3 then script.Parent.TypeArea.Text=j elseif m>2 and script.Parent.TypeArea.TextBounds.Y==24 then tweenToDoubleSize()m=2 elseif m>1 and script.Parent.TypeArea.TextBounds.Y==12 then tweenToNormalSize()m=1 end end j=script.Parent.TypeArea.Text end)while wait(1)do if k>0 then k=k-1 end end
-- Basic settings
local MAX_SPAM_SCORE = 5

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

local defaultMsg = "Tap here to chat"
local previousText = script.Parent.TypeArea.Text
local size = 1
local tweenInProgress = false
local spamScore = 0

function tweenToTripleSize()
	-- Tween size
	tweenInProgress = true
	local goal = { Size = UDim2.new(1, -365, 0, 60) }
	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(1, -365, 0, 48) }
	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(1, -365, 0, 36) }
	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
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
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 == 24 then
			tweenToDoubleSize()
			size = 2
		elseif size > 1 and script.Parent.TypeArea.TextBounds.Y == 12 then
			tweenToNormalSize()
			size = 1
		end
	end

	-- Set previous text
	previousText = script.Parent.TypeArea.Text
end)

while wait(1) do
	-- Decrement spam score
	if spamScore > 0 then
		spamScore = spamScore - 1
	end
end
