--// All global vars will be wiped/replaced except script
--// All guis are autonamed using client.Functions.GetRandom()

return function(data)
	local gui = service.New("ScreenGui")
	local mode = data.Mode
	local gTable = client.UI.Register(gui, {Name = "Effect"})
	local BindEvent = gTable.BindEvent

	client.UI.Remove("Effect", gui)
	gTable:Ready()

	if mode == "Off" or not mode then
		gTable:Destroy()
	elseif mode == "Pixelize" then
		local frame = Instance.new("Frame",gui)
		local camera = workspace.CurrentCamera
		local pixels = {}

		local resY = data.Resolution or 20
		local resX = data.Resolution or 20
		local depth = 0
		local distance = data.Distance or 80

		local function renderScreen()
			for i,pixel in pairs(pixels) do
				local ray = camera:ScreenPointToRay(pixel.X,pixel.Y,depth)
				local part, endPoint = workspace:FindPartOnRay(Ray.new(ray.Origin,ray.Direction*distance))
				if part and part.Transparency < 1 then
					pixel.Pixel.BackgroundColor3 = part.BrickColor.Color
				else
					pixel.Pixel.BackgroundColor3 = Color3.fromRGB(105, 170, 255)
				end
			end
		end

		frame.Size = UDim2.new(1,0,1,40)
		frame.Position = UDim2.new(0,0,0,-35)
		for y = 0,gui.AbsoluteSize.Y+50,resY do
			for x = 0,gui.AbsoluteSize.X+30,resX do
				local pixel = Instance.new("TextLabel")
				pixel.Text = ""
				pixel.BorderSizePixel = 0
				pixel.Size = UDim2.new(0,resX,0,resY)
				pixel.Position = UDim2.new(0,x-(resX/2),0,y-(resY/2))
				pixel.BackgroundColor3 = Color3.fromRGB(105, 170, 255)
				pixel.Parent = frame
				table.insert(pixels,{Pixel = pixel,X = x, Y = y})
			end
		end

		while wait() and not gTable.Destroyed and gui.Parent do 
			if not gTable.Destroyed and not gTable.Active then
				wait(5)
			else
				renderScreen()
			end
		end

		gTable:Destroy()
	elseif mode == "FadeOut" then
		service.StarterGui:SetCore("TopbarEnabled",false)
		service.UserInputService.MouseIconEnabled = false
		for i,v in pairs(service.PlayerGui:GetChildren()) do 
			pcall(function() if v~=gui then v:Destroy() end end) 
		end
		local bg = Instance.new("Frame", gui)
		bg.BackgroundTransparency = 1
		bg.BackgroundColor3 = Color3.new(0,0,0)
		bg.Size = UDim2.new(2,0,2,0)
		bg.Position = UDim2.new(-0.5,0,-0.5,0)
		for i = 1,0,-0.01 do
			bg.BackgroundTransparency = i
			wait(0.1)
		end
		bg.BackgroundTransparency = 0
		client.Functions.BrickBlur(true,0,BrickColor.new("Really black"))
	elseif mode == "Trippy" then
		local v = service.Player
		local bg = Instance.new("Frame", gui) 

		bg.BackgroundColor3 = Color3.new(0,0,0) 
		bg.BackgroundTransparency = 0 
		bg.Size = UDim2.new(10,0,10,0) 
		bg.Position = UDim2.new(-5,0,-5,0) 
		bg.ZIndex = 10

		while gui and gui.Parent do 
			wait(1/44) 
			bg.BackgroundColor3 = Color3.new(math.random(255)/255,math.random(255)/255,math.random(255)/255) 
		end

		if gui then gui:Destroy() end
	elseif mode == "Spooky" then
		local frame = Instance.new("Frame",gui)
		frame.BackgroundColor3=Color3.new(0,0,0)
		frame.Size=UDim2.new(1,0,1,50)
		frame.Position=UDim2.new(0,0,0,-50)
		local img = Instance.new("ImageLabel",frame)
		img.Position = UDim2.new(0,0,0,0)
		img.Size = UDim2.new(1,0,1,0)
		img.BorderSizePixel = 0
		img.BackgroundColor3 = Color3.new(0,0,0)
		local textures = {
			299735022;
			299735054;
			299735082;
			299735103;
			299735133;
			299735156;
			299735177;
			299735198;
			299735219;
			299735245;
			299735269;
			299735289;
			299735304;
			299735320;
			299735332;
			299735361;
			299735379;
		}

		local sound = Instance.new("Sound",gui)
		sound.SoundId = "rbxassetid://174270407"
		sound.Looped = true
		sound:Play()

		while gui and gui.Parent do
			for i=1,#textures do
				img.Image = "rbxassetid://"..textures[i]
				wait(0.1)
			end
		end
		sound:Stop()
	elseif mode == "lifeoftheparty" then
		local frame = Instance.new("Frame",gui)
		frame.BackgroundColor3 = Color3.new(0,0,0)
		frame.Size = UDim2.new(1,0,1,50)
		frame.Position = UDim2.new(0,0,0,-50)
		local img = Instance.new("ImageLabel",frame)
		img.Position = UDim2.new(0,0,0,0)
		img.Size = UDim2.new(1,0,1,0)
		img.BorderSizePixel = 0
		img.BackgroundColor3 = Color3.new(0,0,0)
		local textures = {
			299733203;
			299733248;
			299733284;
			299733309;
			299733355;
			299733386;
			299733404;
			299733425;
			299733472;
			299733489;
			299733501;
			299733523;
			299733544;
			299733551;
			299733564;
			299733570;
			299733581;
			299733597;
			299733609;
			299733621;
			299733632;
			299733640;
			299733648;
			299733663;
			299733674;
			299733694;

		}
		local sound = Instance.new("Sound",gui)
		sound.SoundId = "rbxassetid://172906410"
		sound.Looped = true
		sound:Play()

		while gui and gui.Parent do
			for i=1,#textures do
				img.Image = "rbxassetid://"..textures[i]
				wait(0.1)
			end
		end

		sound:Stop()
	elseif mode == "Strobe" then
		local bg = Instance.new("Frame", gui) 
		bg.BackgroundColor3 = Color3.new(0,0,0) 
		bg.BackgroundTransparency = 0 
		bg.Size = UDim2.new(10,0,10,0) 
		bg.Position = UDim2.new(-5,0,-5,0)
		bg.ZIndex = 10

		while gui and gui.Parent do
			wait(1/44) 
			bg.BackgroundColor3 = Color3.new(1,1,1) 
			wait(1/44) 
			bg.BackgroundColor3 = Color3.new(0,0,0) 
		end
		if gui then gui:Destroy() end
	elseif mode == "Blind" then
		local bg = Instance.new("Frame", gui) 
		bg.BackgroundColor3 = Color3.new(0,0,0) 
		bg.BackgroundTransparency = 0 
		bg.Size = UDim2.new(10,0,10,0) 
		bg.Position = UDim2.new(-5,0,-5,0) 
		bg.ZIndex = 10
	elseif mode == "ScreenImage" then
		local bg = Instance.new("ImageLabel", gui) 
		bg.Image="rbxassetid://"..data.Image
		bg.BackgroundColor3 = Color3.new(0,0,0) 
		bg.BackgroundTransparency = 0 
		bg.Size = UDim2.new(1,0,1,0) 
		bg.Position = UDim2.new(0,0,0,0) 
		bg.ZIndex = 10
	elseif mode == "ScreenVideo" then
		local bg = Instance.new("VideoFrame", gui) 
		bg.Video="rbxassetid://"..data.Video
		bg.BackgroundColor3 = Color3.new(0,0,0) 
		bg.BackgroundTransparency = 0 
		bg.Size = UDim2.new(1,0,1,0) 
		bg.Position = UDim2.new(0,0,0,0) 
		bg.ZIndex = 10
		bg:Play()
	end
end