return function(N,H)if H then setfenv(1,H)end local W=client.UI.Prepare(script.Parent.Parent)local r=service.PlayerGui local a=W.Frame local g=W.Frame.Message local X=W.Frame.Title local x=N.gIndex local b=N.gTable local s=N.Title local B=N.Message local J=N.Scroll local S=N.Time if not N.Message or not N.Title then W:Destroy()end X.Text=s g.Text=B X.TextTransparency=1 g.TextTransparency=1 X.TextStrokeTransparency=1 g.TextStrokeTransparency=1 a.BackgroundTransparency=1 local c=service.New("\066\108\117\114\069\102\102\101\099\116")c.Enabled=false c.Size=0 c.Parent=workspace.CurrentCamera local q=10 local e=10 local i=.1 local D=.5 local h=.3 local G=e/q local z=h/q local y=.1 local v=.1 local R=false local function A()if not R then c.Enabled=true b:Ready()for N=1,q,1 do if c.Size<e then c.Size=c.Size+G end if g.TextTransparency>i then g.TextTransparency=g.TextTransparency-y X.TextTransparency=X.TextTransparency-y end if g.TextStrokeTransparency>D then g.TextStrokeTransparency=g.TextStrokeTransparency-v X.TextStrokeTransparency=X.TextStrokeTransparency-v end if a.BackgroundTransparency>h then a.BackgroundTransparency=a.BackgroundTransparency-z end wait(.016666666666667)end end end local function Y()if not R then for N=1,q,1 do if c.Size>0 then c.Size=c.Size-G end if g.TextTransparency<1 then g.TextTransparency=g.TextTransparency+y X.TextTransparency=X.TextTransparency+y end if g.TextStrokeTransparency<1 then g.TextStrokeTransparency=g.TextStrokeTransparency+v X.TextStrokeTransparency=X.TextStrokeTransparency+v end if a.BackgroundTransparency<1 then a.BackgroundTransparency=a.BackgroundTransparency+z end wait(.016666666666667)end c.Enabled=false c:Destroy();(service.UnWrap(W)):Destroy()R=true end end b.CustomDestroy=function()if not R then R=true pcall(Y)end pcall(function()(service.UnWrap(W)):Destroy()end)pcall(function()c:Destroy()end)end A()wait(S or 5)if not R then Y()end end


return function(data, env)
	if env then
		setfenv(1, env)
	end

	local gui = client.UI.Prepare(script.Parent.Parent) -- Change it to a TextLabel to avoid chat clearing
	local playergui = service.PlayerGui
	local frame = gui.Frame
	local msg = gui.Frame.Message
	local ttl = gui.Frame.Title

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

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

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

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


	local blur = service.New("BlurEffect")
	blur.Enabled = false
	blur.Size = 0
	blur.Parent = workspace.CurrentCamera

	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 gone = false

	local function fadeIn()
		if not gone then
			blur.Enabled = true
			gTable:Ready()
			--gui.Parent = service.PlayerGui
			for i = 1,fadeSteps do
				if blur.Size<blurSize then
					blur.Size = blur.Size+blurStep
				end
				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
				end
				wait(1/60)
			end
		end
	end

	local function fadeOut()
		if not gone then
			for i = 1,fadeSteps do
				if blur.Size>0 then
					blur.Size = blur.Size-blurStep
				end
				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
				end
				wait(1/60)
			end
			blur.Enabled = false
			blur:Destroy()
			service.UnWrap(gui):Destroy()
			gone = true
		end
	end

	gTable.CustomDestroy = function()
		if not gone then
			gone = true
			pcall(fadeOut)
		end

		pcall(function() service.UnWrap(gui):Destroy() end)
		pcall(function() blur:Destroy() end)
	end


	--[[if not scroll then
		msg.Text = message
	else
		Routine(function()
			wait(0.5)
			for i = 1, #message do
				msg.Text = msg.Text .. message:sub(i,i)
				wait(0.05)
			end
		end)
	end--]] -- For now?

	fadeIn()
	wait(tim or 5)
	if not gone then
		fadeOut()
	end

	--[[

	frame.Position = UDim2.new(0.5,-175,-1.5,0)

	gui.Parent = playergui

	frame:TweenPosition(UDim2.new(0.5,-175,0.25,0),nil,nil,0.5)

	if not scroll then
		msg.Text = message
		wait(tim or 10)
	else
		wait(0.5)
		for i = 1, #message do
			msg.Text = msg.Text .. message:sub(i,i)
			wait(0.05)
		end
		wait(tim or 5)
	end

	if frame then
		frame:TweenPosition(UDim2.new(0.5,-175,-1.5,0),nil,nil,0.5)
		wait(1)
		gui:Destroy()
	end
	--]]
end
