local U=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local j=game:GetService("\080\108\097\121\101\114\115")local H=j.LocalPlayer local A=script:WaitForChild("\077\101\115\115\097\103\101\084\097\107\101\111\118\101\114\071\117\105")local Q=A:WaitForChild("\066\097\099\107\103\114\111\117\110\100")local u=A:WaitForChild("\084\101\120\116\076\097\098\101\108")local Y=.5 local z=4 local G=0 local c={}c.ShowMessage=function(j,c)if j then u.Text=j end local g=H:FindFirstChild("\080\108\097\121\101\114\071\117\105")if g then G=G+1 local j=G if not A.Enabled then Q.BackgroundTransparency=1 u.TextTransparency=1 end A.Parent=g A.Enabled=true;(U:Create(Q,TweenInfo.new(Y,Enum.EasingStyle.Quad,Enum.EasingDirection.In),{BackgroundTransparency=0})):Play();(U:Create(u,TweenInfo.new(Y,Enum.EasingStyle.Quad,Enum.EasingDirection.In),{TextTransparency=0})):Play()task.delay(c or z,function()if G==j then(U:Create(Q,TweenInfo.new(Y,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{BackgroundTransparency=1})):Play();(U:Create(u,TweenInfo.new(Y,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{TextTransparency=1})):Play()task.delay(Y,function()if j==G then A.Enabled=false A.Parent=script end end)end end)end end return c
-- Display a message to the client for a short time, with a background that covers the user's screen.

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 = 0.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
