--// All global vars will be wiped/replaced except script


return function(data)
	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 msgr = frame.Right.Message
	local ttlr = frame.Right.Title
	local msgl = frame.Left.Message
	local ttll = frame.Left.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
	
	ttlr.Text = title
	msgr.Text = message
	ttll.Text = title
	msgl.Text = message
	
	local function fadeIn()
		if not gone then
			gTable:Ready()
			frame.Right.Size=UDim2.new(0.5,0,0,72+msgr.TextBounds.Y)
			frame.Left.Size=UDim2.new(0.5,0,0,72+msgl.TextBounds.Y)
			frame.Notify:Play()
			local Tween = game:GetService("TweenService"):Create(frame.Right,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{AnchorPoint=Vector2.new(1, 0.5)})
			local Tween2 = game:GetService("TweenService"):Create(frame.Left,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{AnchorPoint=Vector2.new(0, 0.5)})
			Tween:Play()
			Tween2:Play()
			Tween.Completed:Wait()
		end
	end
	
	local function fadeOut()
		if not gone then
			local Tween = game:GetService("TweenService"):Create(frame.Right,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.In),{AnchorPoint=Vector2.new(0, 0.5)})
			local Tween2 = game:GetService("TweenService"):Create(frame.Left,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.In),{AnchorPoint=Vector2.new(1, 0.5)})
			Tween:Play()
			Tween2:Play()
			Tween.Completed:Wait()
			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)
	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?
	game:GetService("RunService").Heartbeat:wait()
	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
