return function(z,y)if y then setfenv(1,y)end local H=service.Players.LocalPlayer local d=H.PlayerGui local m=script.Parent.Parent local X=m.Frame local b=m.Frame.TextBox local q=m.Frame.ScrollingFrame local i=m.Frame.PlayerList local U=m.Entry local N=gTable.BindEvent local j=false local M=false local P=false local C=false local E=client.Remote.Get("\083\101\116\116\105\110\103",{"\083\112\108\105\116\075\101\121";"\067\111\110\115\111\108\101\075\101\121\067\111\100\101","\066\097\116\099\104\075\101\121","\080\114\101\102\105\120"})local L=E.SplitKey local A=E.ConsoleKeyCode local r=E.BatchKey local R=E.Prefix local g=client.Remote.Get("\070\111\114\109\097\116\116\101\100\067\111\109\109\097\110\100\115")or{}local e=TweenInfo.new(.15)local u=service.TweenService:Create(X,e,{Size=UDim2.new(1,0,0,140)})local s=service.TweenService:Create(X,e,{Size=UDim2.new(1,0,0,40)})local Y=service.TweenService:Create(X,e,{Position=UDim2.new(0,0,0,0)})local Z=service.TweenService:Create(X,e,{Position=UDim2.new(0,0,0,-200)})X.Position=UDim2.new(0,0,0,-200)X.Visible=false X.Size=UDim2.new(1,0,0,40)q.Visible=false if client.Variables.ConsoleOpen then if client.Variables.ChatEnabled then service.StarterGui:SetCoreGuiEnabled("\067\104\097\116",true)end if client.Variables.PlayerListEnabled then service.StarterGui:SetCoreGuiEnabled("\080\108\097\121\101\114\076\105\115\116",true)end if client.UI.Get("\078\111\116\105\102")then(client.UI.Get("\078\111\116\105\102",nil,true)).Object.LABEL.Visible=true end local z=client.UI.Get("\067\104\097\116",nil,true)if z then z.Object.Drag.Visible=true end local y=client.UI.Get("\080\108\097\121\101\114\076\105\115\116",nil,true)if y then y.Object.Drag.Visible=true end local H=client.UI.Get("\072\105\110\116\072\111\108\100\101\114",nil,true)if H then H.Object.Frame.Visible=true end end client.Variables.ChatEnabled=service.StarterGui:GetCoreGuiEnabled("\067\104\097\116")client.Variables.PlayerListEnabled=service.StarterGui:GetCoreGuiEnabled("\080\108\097\121\101\114\076\105\115\116")local function B()if m:IsDescendantOf(game)and not C then C=true q:ClearAllChildren()q.CanvasSize=UDim2.new(0,0,0,0)q.ScrollingEnabled=false X.Size=UDim2.new(1,0,0,40)q.Visible=false i.Visible=false P=false if client.Variables.ChatEnabled then service.StarterGui:SetCoreGuiEnabled("\067\104\097\116",true)end if client.Variables.PlayerListEnabled then service.StarterGui:SetCoreGuiEnabled("\080\108\097\121\101\114\076\105\115\116",true)end if client.UI.Get("\078\111\116\105\102")then(client.UI.Get("\078\111\116\105\102",nil,true)).Object.LABEL.Visible=true end local z=client.UI.Get("\067\104\097\116",nil,true)if z then z.Object.Drag.Visible=true end local y=client.UI.Get("\080\108\097\121\101\114\076\105\115\116",nil,true)if y then y.Object.Drag.Visible=true end local H=client.UI.Get("\072\105\110\116\072\111\108\100\101\114",nil,true)if H then H.Object.Frame.Visible=true end Z:Play()C=false j=false end end local function V()if m:IsDescendantOf(game)and not C then C=true client.Variables.ChatEnabled=service.StarterGui:GetCoreGuiEnabled("\067\104\097\116")client.Variables.PlayerListEnabled=service.StarterGui:GetCoreGuiEnabled("\080\108\097\121\101\114\076\105\115\116")service.StarterGui:SetCoreGuiEnabled("\067\104\097\116",false)service.StarterGui:SetCoreGuiEnabled("\080\108\097\121\101\114\076\105\115\116",false)q.ScrollingEnabled=true i.ScrollingEnabled=true if client.UI.Get("\078\111\116\105\102")then(client.UI.Get("\078\111\116\105\102",nil,true)).Object.LABEL.Visible=false end local z=client.UI.Get("\067\104\097\116",nil,true)if z then z.Object.Drag.Visible=false end local y=client.UI.Get("\080\108\097\121\101\114\076\105\115\116",nil,true)if y then y.Object.Drag.Visible=false end local H=client.UI.Get("\072\105\110\116\072\111\108\100\101\114",nil,true)if H then H.Object.Frame.Visible=false end Y:Play()X.Size=UDim2.new(1,0,0,40)q.Visible=false i.Visible=false P=false b.Text=""X.Visible=true X.Position=UDim2.new(0,0,0,0)b:CaptureFocus()b.Text=""wait()b.Text=""C=false j=true end end b.FocusLost:Connect(function(z)if z then if b.Text~=""and string.len(b.Text)>1 then client.Remote.Send("\080\114\111\099\101\115\115\067\111\109\109\097\110\100",b.Text)end end B()end)b.Changed:Connect(function(z)if z=="\084\101\120\116"and(b.Text~=""and V)then if string.sub(b.Text,string.len(b.Text))=="\t"then if i:FindFirstChild("\069\110\116\114\121 \048")then b.Text=(string.sub(b.Text,1,string.len(b.Text)-1)..i["\069\110\116\114\121 \048"].Text).." "elseif q:FindFirstChild("\069\110\116\114\121 \048")then b.Text=(string.split(q["\069\110\116\114\121 \048"].Text,"\060"))[1]else b.Text=b.Text..R end b.CursorPosition=string.len(b.Text)+1 b.Text=string.gsub(b.Text,"\t","")end q:ClearAllChildren()i:ClearAllChildren()local z=b.Text if string.match(z,"\046\042"..(r.."\040\091\094\'\093\043\041"))then z=string.match(z,"\046\042"..(r.."\040\091\094\'\093\043\041"))z=string.match(z,"\094\037\115\042\040\046-\041\037\115\042\036")end local y=0 local H=string.match(z,"\046\043"..(L.."\040\046\042\041\036"))for d,m in next,service.Players:GetPlayers()do if H and string.sub(string.lower(tostring(m)),1,#H)==string.lower(H)or string.match(z,L.."\036")then local z=U:Clone()z.Text=tostring(m)z.Name="\069\110\116\114\121 "..y z.TextXAlignment="\082\105\103\104\116"z.Visible=true z.Parent=i z.Position=UDim2.new(0,0,0,20*y)z.MouseButton1Down:Connect(function()b.Text=b.Text..tostring(m)b:CaptureFocus()end)y=y+1 end end i.CanvasSize=UDim2.new(0,0,0,y*20)local d=0 for y,H in next,g do if string.sub(string.lower(H),1,#z)==string.lower(z)or string.find(string.lower(H),string.match(string.lower(z),"\094\040\046-\041"..L)or string.lower(z),1,true)then if not P then u:Play()q.Visible=true i.Visible=true P=true end local z=U:Clone()z.Visible=true z.Parent=q z.Text=H z.Name="\069\110\116\114\121 "..d z.Position=UDim2.new(0,0,0,20*d)z.MouseButton1Down:Connect(function()b.Text=z.Text b:CaptureFocus()end)d=d+1 end end X.Size=UDim2.new(1,0,0,math.clamp(d*20+40,40,140))q.CanvasSize=UDim2.new(0,0,0,d*20)elseif z=="\084\101\120\116"and(b.Text==""and j)then s:Play()q.Visible=false i.Visible=false P=false q:ClearAllChildren()q.CanvasSize=UDim2.new(0,0,0,0)end end)service.HookEvent("\084\111\103\103\108\101\067\111\110\115\111\108\101",function()if j then B()else V()end client.Variables.ConsoleOpen=j end)N(service.UserInputService.InputBegan,function(z)local y=service.UserInputService:GetFocusedTextBox()if not y and(rawequal(z.UserInputType,Enum.UserInputType.Keyboard)and z.KeyCode.Name==(client.Variables.CustomConsoleKey or A))then service.Events.ToggleConsole:Fire()end end)gTable:Ready()end


return function(data, env)
	if env then
		setfenv(1, env)
	end
	
	local player = service.Players.LocalPlayer
	local playergui = player.PlayerGui
	local gui = script.Parent.Parent
	local frame = gui.Frame
	local text = gui.Frame.TextBox
	local scroll = gui.Frame.ScrollingFrame
	local players = gui.Frame.PlayerList
	local entry = gui.Entry
	local BindEvent = gTable.BindEvent

	local opened = false
	local scrolling = false
	local scrollOpen = false
	local debounce = false
	local settings = client.Remote.Get("Setting",{"SplitKey","ConsoleKeyCode","BatchKey","Prefix"})
	local splitKey = settings.SplitKey
	local consoleKey = settings.ConsoleKeyCode
	local batchKey = settings.BatchKey
	local prefix = settings.Prefix
	local commands = client.Remote.Get('FormattedCommands') or {}

	local tweenInfo = TweenInfo.new(0.15)----service.SafeTweenSize(frame,UDim2.new(1,0,0,40),nil,nil,0.3,nil,function() if scrollOpen then frame.Size = UDim2.new(1,0,0,140) end end)
	local scrollOpenTween = service.TweenService:Create(frame, tweenInfo, {
		Size = UDim2.new(1, 0, 0, 140);
	})

	local scrollCloseTween = service.TweenService:Create(frame, tweenInfo, {
		Size = UDim2.new(1, 0, 0, 40);
	})

	local consoleOpenTween = service.TweenService:Create(frame, tweenInfo, {
		Position = UDim2.new(0, 0, 0, 0);
	})

	local consoleCloseTween = service.TweenService:Create(frame, tweenInfo, {
		Position = UDim2.new(0, 0, 0, -200);
	})

	frame.Position = UDim2.new(0,0,0,-200)
	frame.Visible = false
	frame.Size = UDim2.new(1,0,0,40)
	scroll.Visible = false

	if client.Variables.ConsoleOpen then
		if client.Variables.ChatEnabled then
			service.StarterGui:SetCoreGuiEnabled("Chat",true)
		end

		if client.Variables.PlayerListEnabled then
			service.StarterGui:SetCoreGuiEnabled('PlayerList',true)
		end
		if client.UI.Get("Notif") then
			client.UI.Get("Notif",nil,true).Object.LABEL.Visible = true
		end

		local scr = client.UI.Get("Chat",nil,true)
		if scr then scr.Object.Drag.Visible = true end

		local scr = client.UI.Get("PlayerList",nil,true)
		if scr then scr.Object.Drag.Visible = true end

		local scr = client.UI.Get("HintHolder",nil,true)
		if scr then scr.Object.Frame.Visible = true end
	end

	client.Variables.ChatEnabled = service.StarterGui:GetCoreGuiEnabled("Chat")
	client.Variables.PlayerListEnabled = service.StarterGui:GetCoreGuiEnabled('PlayerList')

	local function close()
		if gui:IsDescendantOf(game) and not debounce then
			debounce = true
			scroll:ClearAllChildren()
			scroll.CanvasSize = UDim2.new(0,0,0,0)
			scroll.ScrollingEnabled = false
			frame.Size = UDim2.new(1,0,0,40)
			scroll.Visible = false
			players.Visible = false
			scrollOpen = false

			if client.Variables.ChatEnabled then
				service.StarterGui:SetCoreGuiEnabled("Chat",true)
			end

			if client.Variables.PlayerListEnabled then
				service.StarterGui:SetCoreGuiEnabled('PlayerList',true)
			end

			if client.UI.Get("Notif") then
				client.UI.Get("Notif",nil,true).Object.LABEL.Visible = true
			end

			local scr = client.UI.Get("Chat",nil,true)
			if scr then scr.Object.Drag.Visible = true end

			local scr = client.UI.Get("PlayerList",nil,true)
			if scr then scr.Object.Drag.Visible = true end

			local scr = client.UI.Get("HintHolder",nil,true)
			if scr then scr.Object.Frame.Visible = true end

			consoleCloseTween:Play();
			--service.SafeTweenPos(frame,UDim2.new(0,0,0,-200),'Out','Linear',0.2,true)
			--frame:TweenPosition(UDim2.new(0,0,0,-200),'Out','Linear',0.2,true)
			debounce = false
			opened = false
		end
	end

	local function open()
		if gui:IsDescendantOf(game) and not debounce then
			debounce = true
			client.Variables.ChatEnabled = service.StarterGui:GetCoreGuiEnabled("Chat")
			client.Variables.PlayerListEnabled = service.StarterGui:GetCoreGuiEnabled('PlayerList')

			service.StarterGui:SetCoreGuiEnabled("Chat",false)
			service.StarterGui:SetCoreGuiEnabled('PlayerList',false)

			scroll.ScrollingEnabled = true
			players.ScrollingEnabled = true

			if client.UI.Get("Notif") then
				client.UI.Get("Notif",nil,true).Object.LABEL.Visible = false
			end

			local scr = client.UI.Get("Chat",nil,true)
			if scr then scr.Object.Drag.Visible = false end

			local scr = client.UI.Get("PlayerList",nil,true)
			if scr then scr.Object.Drag.Visible = false end

			local scr = client.UI.Get("HintHolder",nil,true)
			if scr then scr.Object.Frame.Visible = false end

			consoleOpenTween:Play();

			frame.Size = UDim2.new(1,0,0,40)
			scroll.Visible = false
			players.Visible = false
			scrollOpen = false
			text.Text = ''
			frame.Visible = true
			frame.Position = UDim2.new(0,0,0,0)
			text:CaptureFocus()
			text.Text = ''
			wait()
			text.Text = ''
			debounce = false
			opened = true
		end
	end

	text.FocusLost:Connect(function(enterPressed)
		if enterPressed then
			if text.Text~='' and string.len(text.Text)>1 then
				client.Remote.Send('ProcessCommand',text.Text)
			end
		end

		close()
	end)

	text.Changed:Connect(function(c)
		if c == 'Text' and text.Text ~= '' and open then
			if string.sub(text.Text, string.len(text.Text)) == "	" then
				if players:FindFirstChild("Entry 0") then
					text.Text = (string.sub(text.Text, 1, (string.len(text.Text) - 1))..players["Entry 0"].Text).." "
				elseif scroll:FindFirstChild("Entry 0") then
					text.Text = string.split(scroll["Entry 0"].Text, "<")[1]
				else
					text.Text = text.Text..prefix
				end
				text.CursorPosition = string.len(text.Text) + 1
				text.Text = string.gsub(text.Text, "	", "")
			end
			scroll:ClearAllChildren()
			players:ClearAllChildren()

			local nText = text.Text
			if string.match(nText,".*"..batchKey.."([^']+)") then
				nText = string.match(nText,".*"..batchKey.."([^']+)")
				nText = string.match(nText,"^%s*(.-)%s*$")
			end

			local pNum = 0
			local pMatch = string.match(nText,".+"..splitKey.."(.*)$")
			for i,v in next,service.Players:GetPlayers() do
				if (pMatch and string.sub(string.lower(tostring(v)),1,#pMatch) == string.lower(pMatch)) or string.match(nText,splitKey.."$") then
					local new = entry:Clone()
					new.Text = tostring(v)
					new.Name = "Entry "..pNum
					new.TextXAlignment = "Right"
					new.Visible = true
					new.Parent = players
					new.Position = UDim2.new(0,0,0,20*pNum)
					new.MouseButton1Down:Connect(function()
						text.Text = text.Text..tostring(v)
						text:CaptureFocus()
					end)
					pNum = pNum+1
				end
			end

			players.CanvasSize = UDim2.new(0,0,0,pNum*20)

			local num = 0
			for i,v in next,commands do
				if string.sub(string.lower(v),1,#nText) == string.lower(nText) or string.find(string.lower(v), string.match(string.lower(nText),"^(.-)"..splitKey) or string.lower(nText), 1, true) then
					if not scrollOpen then
						scrollOpenTween:Play();
						--frame.Size = UDim2.new(1,0,0,140)
						scroll.Visible = true
						players.Visible = true
						scrollOpen = true
					end
					local b = entry:Clone()
					b.Visible = true
					b.Parent = scroll
					b.Text = v
					b.Name = "Entry "..num
					b.Position = UDim2.new(0,0,0,20*num)
					b.MouseButton1Down:Connect(function()
						text.Text = b.Text
						text:CaptureFocus()
					end)
					num = num+1
				end
			end
			frame.Size = UDim2.new(1, 0, 0, math.clamp((num*20)+40, 40, 140))
			scroll.CanvasSize = UDim2.new(0,0,0,num*20)
		elseif c == 'Text' and text.Text == '' and opened then
			scrollCloseTween:Play();
			--service.SafeTweenSize(frame,UDim2.new(1,0,0,40),nil,nil,0.3,nil,function() if scrollOpen then frame.Size = UDim2.new(1,0,0,140) end end)
			scroll.Visible = false
			players.Visible = false
			scrollOpen = false
			scroll:ClearAllChildren()
			scroll.CanvasSize = UDim2.new(0,0,0,0)
		end
	end)

	service.HookEvent('ToggleConsole', function()
		if opened then
			close()
		else
			open()
		end
		client.Variables.ConsoleOpen = opened
	end)
	
	BindEvent(service.UserInputService.InputBegan, function(InputObject)
		local textbox = service.UserInputService:GetFocusedTextBox()
		if not (textbox) and rawequal(InputObject.UserInputType, Enum.UserInputType.Keyboard) and InputObject.KeyCode.Name == (client.Variables.CustomConsoleKey or consoleKey) then
			service.Events.ToggleConsole:Fire()
		end
	end)

	gTable:Ready()
end
