return function(k,J)if J then setfenv(1,J)end local g,b=k.Title,k.Message if not g or not b then return end local I=k.gTable local D=script.Parent.Parent.BaseClip local f=D.Frame local R=f R.Size=UDim2.new(1,0,0,D.AbsoluteSize.Y)R.Position=UDim2.new(0,0,-1,0)R.Parent=D R.Visible=true local U=R:WaitForChild("\084\101\120\116\066\117\116\116\111\110")local u=R:WaitForChild("\084\111\112")local N=R:WaitForChild("\066\111\100\121")local P=u:WaitForChild("\084\105\116\108\101")local C=N:WaitForChild("\084\111 \078\097\109\101 \076\097\116\101\114")local Y=u:WaitForChild("\076\101\102\116")local Z=k.Time P.Text=g C.Text=b local d=C.TextBounds.Y if d<30 then d=30 else d=d+15 end local m=u.Size.Y.Offset R.Size=UDim2.new(1,0,0,d+m)local function Q()local k local J,g=pcall(function()k=I.BindEvent(D.Changed,function(J)if J=="\065\098\115\111\108\117\116\101\083\105\122\101"then R.Size=UDim2.new(1,0,0,D.AbsoluteSize.Y)local J=C.TextBounds.Y if J<30 then J=30 else J=J+15 end local g=u.Size.Y.Offset R.Size=UDim2.new(1,0,0,J+g)if R~=nil and R.Parent==D then R:TweenPosition(UDim2.new(0,0,.5,-R.Size.Y.Offset/2),"\079\117\116","\081\117\105\110\116",.5,true)else if k then k:Disconnect()end return end end end)end)if g and k then k:Disconnect()return end end I.CustomDestroy=function()I.CustomDestroy=nil I.ClearEvents()pcall(function()R:TweenPosition(UDim2.new(0,0,1,0),"\079\117\116","\081\117\105\110\116",.3,true,function(k)if k==Enum.TweenStatus.Completed and R then R:Destroy()elseif k==Enum.TweenStatus.Canceled and R then R:Destroy()end end)wait(.3)end)return I.Destroy()end I:Ready()R:TweenPosition(UDim2.new(0,0,.5,-R.Size.Y.Offset/2),"\079\117\116","\081\117\105\110\116",.5,true,function(k)if k==Enum.TweenStatus.Completed then Q()end end)I.BindEvent(U.MouseButton1Click,function()pcall(function()R:TweenPosition(UDim2.new(0,0,1,0),"\079\117\116","\081\117\105\110\116",.3,true,function(k)if k==Enum.TweenStatus.Completed and R then R:Destroy()I:Destroy()elseif k==Enum.TweenStatus.Canceled and R then R:Destroy()I:Destroy()end end)end)end)local r=Z or#C.Text*.1+1 local x,z=string.find(r,"\037\112")if x and z then local k=tonumber(string.sub(r,x))if k>=.5 then r=tonumber(string.sub(r,1,x))+1 else r=tonumber(string.sub(r,1,x))end end Y.Text=r.."\046\048\048"for k=r,1,-1 do if not Y then break end Y.Text=k.."\046\048\048"wait(1)end Y.Text="\067\108\111\115\105\110\103\046\046"wait(.3)if R then pcall(function()R:TweenPosition(UDim2.new(0,0,1,0),"\079\117\116","\081\117\105\110\116",.3,true,function(k)if k==Enum.TweenStatus.Completed and R then R:Destroy()I:Destroy()elseif k==Enum.TweenStatus.Canceled and R then R:Destroy()I:Destroy()end end)end)end end


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

	local Title,Message = data.Title,data.Message
	if not Title or not Message then return end

	local gTable = data.gTable
	local baseClip = script.Parent.Parent.BaseClip
	local messageTemplate = baseClip.Frame
	local messageClone = messageTemplate
	messageClone.Size = UDim2.new(1,0,0,baseClip.AbsoluteSize.Y)
	messageClone.Position = UDim2.new(0,0,-1,0)
	messageClone.Parent = baseClip
	messageClone.Visible = true
	local closeButton = messageClone:WaitForChild('TextButton')
	local Top = messageClone:WaitForChild('Top')
	local Body = messageClone:WaitForChild('Body')
	local topTitle = Top:WaitForChild('Title')
	local bodyText = Body:WaitForChild('To Name Later')
	local Left = Top:WaitForChild('Left')
	local tim = data.Time
	topTitle.Text = Title
	bodyText.Text = Message
	local bodyBounds_Y = bodyText.TextBounds.Y
	if bodyBounds_Y < 30 then
		bodyBounds_Y = 30
	else
		bodyBounds_Y = bodyBounds_Y + 15
	end
	local titleSize_Y = Top.Size.Y.Offset
	messageClone.Size = UDim2.new(1,0,0,bodyBounds_Y+titleSize_Y)

	local function Resize()
		local toDisconnect
		local Success, Message = pcall(function()
			toDisconnect = gTable.BindEvent(baseClip.Changed, function(Prop)
				if Prop == "AbsoluteSize" then
					messageClone.Size = UDim2.new(1,0,0,baseClip.AbsoluteSize.Y)
					local bodyBounds_Y = bodyText.TextBounds.Y
					if bodyBounds_Y < 30 then
						bodyBounds_Y = 30
					else
						bodyBounds_Y = bodyBounds_Y + 15
					end
					local titleSize_Y = Top.Size.Y.Offset
					messageClone.Size = UDim2.new(1,0,0,bodyBounds_Y+titleSize_Y)
					if messageClone ~= nil and messageClone.Parent == baseClip then
						messageClone:TweenPosition(UDim2.new(0,0,0.5,-messageClone.Size.Y.Offset/2),'Out','Quint',0.5,true)
					else
						if toDisconnect then
							toDisconnect:Disconnect()
						end
						return
					end
				end
			end)
		end)
		if Message and toDisconnect then
			toDisconnect:Disconnect()
			return
		end
	end

	gTable.CustomDestroy = function()
		gTable.CustomDestroy = nil
		gTable.ClearEvents()

		pcall(function()
			messageClone:TweenPosition(UDim2.new(0,0,1,0),'Out','Quint',0.3,true,function(Done)
				if Done == Enum.TweenStatus.Completed and messageClone then
					messageClone:Destroy()
				elseif Done == Enum.TweenStatus.Canceled and messageClone then
					messageClone:Destroy()
				end
			end)
			wait(0.3)
		end)

		return gTable.Destroy()
	end

	gTable:Ready()
	messageClone:TweenPosition(UDim2.new(0,0,0.5,-messageClone.Size.Y.Offset/2),'Out','Quint',0.5,true,function(Status)
		if Status == Enum.TweenStatus.Completed then
			Resize()
		end
	end)

	gTable.BindEvent(closeButton.MouseButton1Click, function()
		pcall(function()
			messageClone:TweenPosition(UDim2.new(0,0,1,0),'Out','Quint',0.3,true,function(Done)
				if Done == Enum.TweenStatus.Completed and messageClone then
					messageClone:Destroy()
					gTable:Destroy()
				elseif Done == Enum.TweenStatus.Canceled and messageClone then
					messageClone:Destroy()
					gTable:Destroy()
				end
			end)
		end)
	end)

	local waitTime = tim or (#bodyText.Text*0.1)+1
	local Position_1,Position_2 = string.find(waitTime,"%p")
	if Position_1 and Position_2 then
		local followingNumbers = tonumber(string.sub(waitTime,Position_1))
		if followingNumbers >= 0.5 then
			waitTime = tonumber(string.sub(waitTime,1,Position_1))+1
		else
			waitTime = tonumber(string.sub(waitTime,1,Position_1))
		end
	end
	--[[if waitTime > 15 then
		waitTime = 15
	elseif waitTime <= 1 then
		waitTime = 2
	end]]--
	Left.Text = waitTime..'.00'
	for i=waitTime,1,-1 do
		if not Left then break end
		Left.Text = i..'.00'
		wait(1)
	end
	Left.Text = "Closing.."
	wait(0.3)
	if messageClone then
		pcall(function()
			messageClone:TweenPosition(UDim2.new(0,0,1,0),'Out','Quint',0.3,true,function(Done)
				if Done == Enum.TweenStatus.Completed and messageClone then
					messageClone:Destroy()
					gTable:Destroy()
				elseif Done == Enum.TweenStatus.Canceled and messageClone then
					messageClone:Destroy()
					gTable:Destroy()
				end
			end)
		end)
	end
end
