return function(x,N)if N then setfenv(1,N)end local J=script.Parent.Parent local T=J.Frame local X=T.Frame local h=X.Message local g=X.Title local j=X.Left local z=x.gIndex local K=x.gTable local P=x.Title local E=x.Message local m=x.Scroll local G=x.Time local n=false if not x.Message or not x.Title then K:Destroy()end g.Text=P h.Text=E g.TextTransparency=1 h.TextTransparency=1 g.TextStrokeTransparency=1 h.TextStrokeTransparency=1 T.BackgroundTransparency=1 local p={Type="\083\109\097\108\108 \083\099\114\101\101\110 \077\101\115\115\097\103\101",Title=P,Message=E;Icon="\114\098\120\097\115\115\101\116\105\100\058\047\047\055\053\048\049\049\055\053\055\048\056",Time=os.date("\037\088"),Function=nil}table.insert(client.Variables.CommunicationsHistory,p)service.Events.CommsCenter:Fire(p)local y=10 local f=10 local c=.1 local Q=.5 local I=.3 local F=f/y local l=I/y local s=.1 local i=.1 local function O()K:Ready()for x=1,y,1 do if h.TextTransparency>c then h.TextTransparency=h.TextTransparency-s g.TextTransparency=g.TextTransparency-s end if h.TextStrokeTransparency>Q then h.TextStrokeTransparency=h.TextStrokeTransparency-i g.TextStrokeTransparency=g.TextStrokeTransparency-i end if T.BackgroundTransparency>I then T.BackgroundTransparency=T.BackgroundTransparency-l X.BackgroundTransparency=T.BackgroundTransparency end service.Wait("\083\116\101\112\112\101\100")end end local function b()if not n then n=true for x=1,y,1 do if h.TextTransparency<1 then h.TextTransparency=h.TextTransparency+s g.TextTransparency=g.TextTransparency+s end if h.TextStrokeTransparency<1 then h.TextStrokeTransparency=h.TextStrokeTransparency+i g.TextStrokeTransparency=g.TextStrokeTransparency+i end if T.BackgroundTransparency<1 then T.BackgroundTransparency=T.BackgroundTransparency+l X.BackgroundTransparency=T.BackgroundTransparency end service.Wait("\083\116\101\112\112\101\100")end;(service.UnWrap(J)):Destroy()end end K.CustomDestroy=function()b()end O()if not G then local x,N=E:gsub(" ","")N=math.clamp(N/2,4,11)+1 j.Text="\091"..(N.."\093")for x=N,1,-1 do if not j then break end j.Text="\091"..(x.."\093")wait(1)end else j.Text="\091"..(G.."\093")for x=G,1,-1 do if not j then break end j.Text="\091"..(x.."\093")wait(1)end end j.Text="\091\067\108\111\115\105\110\103\093"wait(.3)if not n then b()end end


return function(data, env)
	if env then
		setfenv(1, env)
	end
	local gui = script.Parent.Parent--client.UI.Prepare(script.Parent.Parent)
	local frame = gui.Frame
	local frame2 = frame.Frame
	local msg = frame2.Message
	local ttl = frame2.Title
	local Left = frame2.Left

	local gIndex = data.gIndex
	local gTable = data.gTable

	local title = data.Title
	local message = data.Message
	local scroll = data.Scroll
	local tim = data.Time

	local gone = false

	if not data.Message or not data.Title then gTable:Destroy() end

	ttl.Text = title
	msg.Text = message
	ttl.TextTransparency = 1
	msg.TextTransparency = 1
	ttl.TextStrokeTransparency = 1
	msg.TextStrokeTransparency = 1
	frame.BackgroundTransparency = 1

	local log  = {
		Type = "Small Screen Message";
		Title = title;
		Message = message;
		Icon = "rbxassetid://7501175708";
		Time = os.date("%X");
		Function = nil;
	}

	table.insert(client.Variables.CommunicationsHistory, log)
	service.Events.CommsCenter:Fire(log)

	local fadeSteps = 10
	local blurSize = 10
	local textFade = 0.1
	local strokeFade = 0.5
	local frameFade = 0.3

	local blurStep = blurSize/fadeSteps
	local frameStep = frameFade/fadeSteps
	local textStep = 0.1
	local strokeStep = 0.1

	local function fadeIn()
		gTable:Ready()
		for i = 1,fadeSteps do
			if msg.TextTransparency>textFade then
				msg.TextTransparency = msg.TextTransparency-textStep
				ttl.TextTransparency = ttl.TextTransparency-textStep
			end
			if msg.TextStrokeTransparency>strokeFade then
				msg.TextStrokeTransparency = msg.TextStrokeTransparency-strokeStep
				ttl.TextStrokeTransparency = ttl.TextStrokeTransparency-strokeStep
			end
			if frame.BackgroundTransparency>frameFade then
				frame.BackgroundTransparency = frame.BackgroundTransparency-frameStep
				frame2.BackgroundTransparency = frame.BackgroundTransparency
			end
			service.Wait("Stepped")
		end
	end

	local function fadeOut()
		if not gone then
			gone = true
			for i = 1,fadeSteps do
				if msg.TextTransparency<1 then
					msg.TextTransparency = msg.TextTransparency+textStep
					ttl.TextTransparency = ttl.TextTransparency+textStep
				end
				if msg.TextStrokeTransparency<1 then
					msg.TextStrokeTransparency = msg.TextStrokeTransparency+strokeStep
					ttl.TextStrokeTransparency = ttl.TextStrokeTransparency+strokeStep
				end
				if frame.BackgroundTransparency<1 then
					frame.BackgroundTransparency = frame.BackgroundTransparency+frameStep
					frame2.BackgroundTransparency = frame.BackgroundTransparency
				end
				service.Wait("Stepped")
			end
			service.UnWrap(gui):Destroy()
		end
	end

	gTable.CustomDestroy = function()
		fadeOut()
	end

	fadeIn()
	if not tim then
		local _,time = message:gsub(" ","")
		time = math.clamp(time/2,4,11)+1
		Left.Text = '['..time..']'
		for i=time,1,-1 do
			if not Left then break end
			Left.Text = '['..i..']'
			wait(1)
		end
	else
		Left.Text = '['..tim..']'
		for i=tim,1,-1 do
			if not Left then break end
			Left.Text = '['..i..']'
			wait(1)
		end
	end
	Left.Text = '[Closing]'
	wait(0.3)
	if not gone then
		fadeOut()
	end
end
