local d=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local M=game:GetService("\080\108\097\121\101\114\115")local b=M.LocalPlayer local f=script:WaitForChild("\077\101\115\115\097\103\101\084\097\107\101\111\118\101\114\071\117\105")local t=f:WaitForChild("\066\097\099\107\103\114\111\117\110\100")local v=f:WaitForChild("\084\101\120\116\076\097\098\101\108")local w=.5 local h=4 local n=0 local C={}C.ShowMessage=function(M,C)if M then v.Text=M end local E=b:FindFirstChild("\080\108\097\121\101\114\071\117\105")if E then n=n+1 local M=n if not f.Enabled then t.BackgroundTransparency=1 v.TextTransparency=1 end f.Parent=E f.Enabled=true;(d:Create(t,TweenInfo.new(w,Enum.EasingStyle.Quad,Enum.EasingDirection.In),{BackgroundTransparency=0})):Play();(d:Create(v,TweenInfo.new(w,Enum.EasingStyle.Quad,Enum.EasingDirection.In),{TextTransparency=0})):Play()task.delay(C or h,function()if n==M then(d:Create(t,TweenInfo.new(w,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{BackgroundTransparency=1})):Play();(d:Create(v,TweenInfo.new(w,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{TextTransparency=1})):Play()task.delay(w,function()if M==n then f.Enabled=false f.Parent=script end end)end end)end end return C



local tweenService = game:GetService('TweenService')
local playersService = game:GetService('Players')
local localPlayer = playersService.LocalPlayer
local gui = script:WaitForChild('MessageTakeoverGui')
local background = gui:WaitForChild('Background')
local textLabel = gui:WaitForChild('TextLabel')


local TRANSITION_TIME = .5
local DEFAULT_MESSAGE_DURATION = 4

local changeIndex = 0
local messageTakeoverModule = {}


messageTakeoverModule.ShowMessage = function(text, duration)
	if text then
		textLabel.Text = text
	end
	local playerGui = localPlayer:FindFirstChild('PlayerGui')
	if playerGui then
		changeIndex = changeIndex + 1
		local thisChangeIndex = changeIndex
		
		if not gui.Enabled then
			background.BackgroundTransparency = 1
			textLabel.TextTransparency = 1
		end
		gui.Parent = playerGui
		gui.Enabled = true
		
		-- Transition message in
		tweenService:Create(background,
			TweenInfo.new(TRANSITION_TIME, Enum.EasingStyle.Quad, Enum.EasingDirection.In),
			{['BackgroundTransparency'] = 0,}
		):Play()
		tweenService:Create(textLabel,
			TweenInfo.new(TRANSITION_TIME, Enum.EasingStyle.Quad, Enum.EasingDirection.In),
			{['TextTransparency'] = 0,}
		):Play()
		
		-- Wait the message duration without yielding
		task.delay(duration or DEFAULT_MESSAGE_DURATION, function()
			if changeIndex == thisChangeIndex then
				
				-- Transition message out
				tweenService:Create(background,
					TweenInfo.new(TRANSITION_TIME, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
					{['BackgroundTransparency'] = 1,}
				):Play()
				tweenService:Create(textLabel,
					TweenInfo.new(TRANSITION_TIME, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
					{['TextTransparency'] = 1,}
				):Play()
				
				task.delay(TRANSITION_TIME, function()
					if thisChangeIndex == changeIndex then
						-- Finalize a few things when transition is done
						gui.Enabled = false
						gui.Parent = script
					end
				end)
				
			end
		end)
	end
end


return messageTakeoverModule
