--		local tix = Instance.new("TextButton", cl) 
--		tix.Style = "Custom" 
--		tix.Size = UDim2.new(0,35,1,0)
--		tix.TextScaled=true 
--		tix.Position = UDim2.new(1,-75,0,0) 
--		tix.ZIndex = 2
--		tix.Font = "Arial"
--		tix.FontSize = "Size18" 
--		tix.Text = "TIX" 
--		tix.BackgroundColor3=Color3.new(1,1,0)
--		tix.BorderSizePixel=0
--		tix.TextColor3=Color3.new(1,1,1)
--		tix.BackgroundTransparency=0.5
--		tix.MouseButton1Click:connect(function() 
--			service.MarketPlace:PromptPurchase(localplayer,v.ID,false,Enum.CurrencyType.Tix)
--		end)

		extraPane.CanvasSize=UDim2.new(0,0,(num+1)/20,0)
		num = num +1
	end
	extraPane.CanvasSize=UDim2.new(0,0,(num+1)/20,0)
	
	robux.MouseButton1Click:connect(function()
		service.MarketPlace:PromptPurchase(localplayer, pass[1])
	end)
	
	--tickets.MouseButton1Click:connect(function()
	--	service.MarketPlace:PromptPurchase(localplayer,pass[1],false,Enum.CurrencyType.Tix)
	--end)
	
	extra.MouseButton1Click:connect(function()
		service.MarketPlace:PromptPurchase(localplayer,304651585)
		--[[
		if not extraPane.Visible then
			extraPane.Visible = true
		else
			extraPane.Visible = false
		end--]]
	end)
	
	if playerData.isDonor then
		status.Text = "Donated"
		capeTexture.TextTransparency=0
		capeMaterial.TextTransparency=0
		capeColor.TextTransparency=0
		capeColor.BackgroundTransparency=0
		capeToggle.TextTransparency=0
		
		local ored,ogreen,oblue = 255*currentColor.r,255*currentColor.g,255*currentColor.b
		local newColor = currentColor
		local debounce = false
		
		local function updateStatus()
			status.Text = "Updating..."
			status.Text = client.Remote.Get("UpdateDonor",playerData.Donor)
			wait(0.5)
			status.Text = "Donated"
		end
		
		local function showColorPicker()
			color.BackgroundColor3 = currentColor
			red.Text = ored
			green.Text = ogreen
			blue.Text = oblue
			materialPicker.Visible = false
			texturePicker.Visible = false
			colorPicker.Visible = true
		end
		
		local function showMaterialPicker()
			materialPicker.Visible = true
			texturePicker.Visible = false
			colorPicker.Visible = false
		end
		
		local function showTexturePicker()
			texturePicker.Frame.ID.Text = currentTexture
			texturePicker.Frame.Image.Image = "rbxassetid://"..currentTexture
			materialPicker.Visible = false
			texturePicker.Visible = true
			colorPicker.Visible = false
		end
		
		-- Color Picker
		
		local function updateColor()
			local nred,ngreen,nblue = tonumber(red.Text),tonumber(green.Text),tonumber(blue.Text)
			if not nred then
				nred = 0
			end
			if not ngreen then 
				ngreen = 0
			end
			if not nblue then 
				nblue = 0
			end
			if nred>255 then nred=255 end
			if ngreen>255 then ngreen=255 end
			if nblue>255 then nblue=255 end
			nred = math.floor(nred)
			ngreen = math.floor(ngreen)
			nblue = math.floor(nblue)
			red.Text = nred
			green.Text = ngreen
			blue.Text = nblue
			nred,ngreen,nblue = nred/255,ngreen/255,nblue/255
			newColor = Color3.new(nred,ngreen,nblue)
			color.BackgroundColor3 = newColor
		end
		
		red.Changed:connect(updateColor)
		green.Changed:connect(updateColor)
		blue.Changed:connect(updateColor)
		
		confirmColor.MouseButton1Click:connect(function()
			if not debounce then
				debounce = true
				playerData.Donor.Cape.Color = {newColor.r,newColor.g,newColor.b}
				capeColor.BackgroundColor3 = newColor
				ored,ogreen,oblue = newColor.r*255,newColor.g*255,newColor.b*255
				currentColor = newColor
				colorPicker.Visible = false
				updateStatus()
				debounce = false
			end
		end)
		
		cancelColor.MouseButton1Click:connect(function()
			newColor = currentColor
			colorPicker.Visible = false
		end)
		
		-- Material Picker
		
		local materials = {
			"Brick";
			"Cobblestone";
			"Concrete";
			"CorrodedMetal";
			"DiamondPlate";
			"Fabric";
			"Foil";
			"Granite";
			"Grass";
			"Ice";
			"Marble";
			"Metal";
			"Neon";
			"Pebble";
			"Plastic";
			"Sand";
			"Slate";
			"SmoothPlastic";
			"Wood";
			"WoodPlanks";
			"Glass";
		}
		
		local materialEntry = materialPicker.Entry
		local matNum = 0
		for i,v in pairs(materials) do
			local NewClone = materialEntry:clone()
			NewClone.Parent = materialPicker.Frame
			NewClone.Position = UDim2.new(0, 0, 0, matNum*20)
			NewClone.Text = v
			NewClone.Visible = true
			NewClone.MouseButton1Click:connect(function()
				if not debounce then
					debounce = true
					capeMaterial.Text = v
					playerData.Donor.Cape.Material = v
					materialPicker.Visible = false
					updateStatus()
					debounce = false
				end
			end)
			matNum = matNum+1
			materialPicker.Frame.CanvasSize = UDim2.new(0, 0, 0, matNum*20)
		end
		
		-- Texture Picker
		
		local textureId = texturePicker.Frame.ID
		local confirmId = texturePicker.Frame.Confirm
		local cancelId = texturePicker.Frame.Cancel
		local preview = texturePicker.Frame.Image		
		
		local newId = currentTexture
		textureId.FocusLost:connect(function(enterPressed)
			if enterPressed then
				newId = tonumber(texturePicker.Frame.ID.Text)
				if not newId then
					textureId.Text = "Invalid!"
					wait(1)
					textureId.Text = currentTexture
					preview.Image = "rbxassetid://"..currentTexture
				else
					capeTexture.Text = newId
					preview.Image = "rbxassetid://"..newId
				end
			end
		end)
		
		confirmId.MouseButton1Click:connect(function()
			if not debounce then
				debounce = true
				capeTexture.Text = newId
				playerData.Donor.Cape.Image = newId
				texturePicker.Visible = false
				updateStatus()
				debounce = false
			end
		end)
		
		cancelId.MouseButton1Click:connect(function()
			texturePicker.Visible = false
		end)
		
		-- Other 
		
		
		capeToggle.MouseButton1Click:connect(function()
			if not debounce then
				debounce = true
				if playerData.Donor.Enabled then
					playerData.Donor.Enabled = false
					capeToggle.Text = "Disabled"
				elseif not playerData.Donor.Enabled then
					playerData.Donor.Enabled = true
					capeToggle.Text = "Enabled"
				end
				updateStatus()
				debounce = false
			end
		end)
		
		capeMaterial.MouseButton1Click:connect(function()
			if not materialPicker.Visible then
				showMaterialPicker()
			end
		end)
		
		capeTexture.MouseButton1Click:connect(function()
			if not texturePicker.Visible then
				showTexturePicker()
			end
		end)
		
		capeColor.MouseButton1Click:connect(function()
			if not colorPicker.Visible then
				showColorPicker()
			end
		end)
	else
		status.Text = "Not a Donor"
		capeTexture.TextTransparency=0.5
		capeMaterial.TextTransparency=0.5
		capeColor.TextTransparency=0.5
		capeColor.BackgroundTransparency=0.5
		capeToggle.TextTransparency=0.5
	end
	-- Keybinds
	
	local Keybinds = keybindsTab.Keybinds
	local addBind = keybindsTab.Add
	local editBind = keybindsTab.Edit
	local removeBind = keybindsTab.Removeb
	local bindEntry = keybindsTab.Entry
	
	local makeBind = addBind.AddBind
	local confirmBind = makeBind.Add
	local cancelBind = makeBind.Cancel
	local command = makeBind.Command
	local bindKey = makeBind.BindKey
	
	local keyEntry = keybindsTab.Entry
	
	local selectedKey
	local selectedCommand
	local selectedEntry
	
	local newBind
	
	local bindListener
	bindKey.MouseButton1Click:connect(function()
		client.Variables.WaitingForBind = true
		bindKey.Text = "Waiting for key press..."
		bindListener = service.UserInputService.InputBegan:connect(function(input)
			if input.KeyCode then
				newBind = input.KeyCode.Value
				client.Variables.WaitingForBind = false
				bindListener:disconnect()
				bindListener = nil
				bindKey.Text = string.char(newBind)
			end
		end)
	end)
	
	local function getBinds()
		local num = 0
		selectedKey = nil
		selectedCommand = nil
		selectedEntry = nil
		Keybinds:ClearAllChildren()
		for i,v in pairs(client.Variables.KeyBinds) do
			local clone = keyEntry:clone()
			clone.Text = "Key: "..string.char(i).." | Command: "..v
			clone.Position = UDim2.new(0,0,0,num*20)
			clone.Visible = true
			clone.Parent = Keybinds
			clone.MouseButton1Click:connect(function()
				if selectedEntry then 
					selectedEntry.BackgroundTransparency = 1
				end
				clone.BackgroundTransparency = 0
				selectedKey = i
				selectedCommand = v
				selectedEntry = clone
			end)
			num = num + 1
		end
		Keybinds.CanvasSize = UDim2.new(0,0,0,num*20)
	end
	
	confirmBind.MouseButton1Click:connect(function()
		if command.Text~="" and newBind then
			client.Functions.AddKeyBind(newBind,command.Text)
			makeBind.Visible = false
			newBind = nil
			command.Text = ""
			bindKey.Text = "Click to Bind"
			getBinds()
		end
	end)
	
	cancelBind.MouseButton1Click:connect(function()
		makeBind.Visible = false
		newBind = nil
		command.Text = ""
		bindKey.Text = "Click to Bind"
		client.Variables.WaitingForBind = false
		if bindListener then bindListener:disconnect() end
		bindListener = nil
	end)
	
	addBind.MouseButton1Click:connect(function()
		if not makeBind.Visible then
			newBind = nil
			command.Text = ""
			bindKey.Text = "Click to Bind"
			makeBind.Visible = true
		end
	end)
	
	editBind.MouseButton1Click:connect(function()
		if selectedKey and selectedCommand and selectedEntry then
			newBind = nil
			command.Text = selectedCommand
			bindKey.Text = string.char(selectedKey)
			makeBind.Visible = true
		end
	end)
	
	removeBind.MouseButton1Click:connect(function()
		if selectedKey and selectedCommand and selectedEntry then
			client.Functions.RemoveKeyBind(selectedKey)
			getBinds()
		end
	end)
	
	getBinds()
	
	--Settings
	
	local SettingsScroll = settingsTab.Settings
	local settingData = client.Remote.Get("AllSettings")
	if not 	gui.Parent then return end
	
	if settingData and type(settingData)=="table" then 
		settings.Visible = true
		
		local sets,descs,order = settingData.Settings,settingData.Descs,settingData.Order
		
		local num = 1
		local clear = toggleBut:clone()
		clear.Text = "Click 'Clear' to clear all saved settings"
		clear.TextButton.Text = "Clear"
		clear.TextButton.MouseButton1Click:connect(function()
			client.Remote.Send("ClearSavedSettings")
		end)
		clear.Visible = true
		Expand(clear, desc)
		clear.Desc.Value = "Clears all saved settings"
		clear.Position = UDim2.new(0,0,0,0)
		clear.Parent = settingsTab.Settings
		for i,set in pairs(order) do
			local v = sets[set]
			if set == " " then
				local clone = stringBut:Clone()
				clone.Text = " "
				clone.TextBox.Visible = false
				clone.Position = UDim2.new(0,0,0,num*20)
				clone.Visible = true
				clone.Parent = settingsTab.Settings
				num = num+1
			elseif v~=nil then 
				if type(v)=="string" or type(v)=="number" then
					if set == "Theme" or set == "MobileTheme" then
						local clone = toggleBut:Clone()
						local materialPicker = materialPicker:Clone()
						materialPicker.Parent = clone
						local materialEntry = materialPicker.Entry
						
						materialPicker.Position = UDim2.new(1,-200,0,0)
						
						local function showPicker()
							local matNum = 0
							local themes = {}
							
							for i,v in pairs(client.Deps.UI:GetChildren()) do
								table.insert(themes,v.Name)
							end
							
							materialPicker.Frame:ClearAllChildren()
							for i,v in pairs(themes) do
								local NewClone = materialEntry:clone()
								NewClone.Parent = materialPicker.Frame
								NewClone.Position = UDim2.new(0, 0, 0, matNum*20)
								NewClone.Text = v
								NewClone.Visible = true
								NewClone.MouseButton1Click:connect(function()
									materialPicker.Visible = false
									clone.TextButton.Text = v
									sets[set] = v
									client.Remote.Send("SaveSetSetting",set,v)
								end)
								matNum = matNum+1
								materialPicker.Frame.CanvasSize = UDim2.new(0, 0, 0, matNum*20)
							end --// #lazySunday
							
							materialPicker.Visible = true
						end
						
						clone.Text = set..": "
						if descs[set] then
							clone.Desc.Value = descs[set]
						else
							clone.Desc.Value = set
						end
						clone.Position = UDim2.new(0,0,0,num*20)
						clone.Visible = true
						Expand(clone,desc)
						clone.TextButton.Text = v
						clone.TextButton.MouseButton1Down:connect(function()
							showPicker()
						end)
						clone.Parent = settingsTab.Settings
						num = num+1
					else
						local clone = stringBut:Clone()
						clone.Text = set..": "
						clone.TextBox.Text = v
						if descs[set] then
							clone.Desc.Value = descs[set]
						else
							clone.Desc.Value = set
						end
						clone.Position = UDim2.new(0,0,0,num*20)
						clone.Visible = true
						Expand(clone,desc)
						clone.TextBox.FocusLost:connect(function(enterPressed)
							if enterPressed then 
								if type(v) == "number" then
									if tonumber(clone.TextBox.Text) then
										sets[set] = tonumber(clone.TextBox.Text)
										client.Remote.Send("SaveSetSetting",set,sets[set])
									else
										clone.TextBox.Text = v
									end
								else
									sets[set] = clone.TextBox.Text
									client.Remote.Send("SaveSetSetting",set,sets[set])
								end
							else
								clone.TextBox.Text = v
							end
						end)
						clone.Parent = settingsTab.Settings
						num = num+1
					end
				elseif type(v)=="boolean" then
					local clone = toggleBut:Clone()
					clone.Text = set..": "
					if descs[set] then
						clone.Desc.Value = descs[set]
					else
						clone.Desc.Value = set
					end
					clone.Position = UDim2.new(0,0,0,num*20)
					clone.Visible = true
					Expand(clone,desc)
					local enabled = v
					if enabled then
						clone.TextButton.Text = "Enabled"
					else
						clone.TextButton.Text = "Disabled"
					end
					clone.TextButton.MouseButton1Down:connect(function()
						if enabled then 
							sets[set] = false
							enabled = false
							clone.TextButton.Text = "Disabled"
							client.Remote.Send("SaveSetSetting",set,sets[set])
						else
							sets[set] = true
							enabled = true
							clone.TextButton.Text = "Enabled"
							client.Remote.Send("SaveSetSetting",set,sets[set])
						end
					end)
					clone.Parent = settingsTab.Settings
					num = num+1
				elseif type(v)=="userdata" then
					if set=="TopbarColor" then
						local clone = colorBut:Clone()
						clone.Text = set..": "
						if descs[set] then
							clone.Desc.Value = descs[set]
						else
							clone.Desc.Value = set
						end
						clone.Position = UDim2.new(0,0,0,num*20)
						clone.Visible = true
						Expand(clone,desc)
						clone.TextButton.BackgroundColor3 = v
						
						local ored,ogreen,oblue = v.r*255,v.g*255,v.b*255
						
						local colorPicker = clone.ColorPicker
						colorPicker.Parent = settingsTab
						colorPicker.Position = UDim2.new(1,20,0,0)
						
						local red = colorPicker.Frame.R
						local green = colorPicker.Frame.G
						local blue = colorPicker.Frame.B
						local color = colorPicker.Frame.Color
						local confirmColor = colorPicker.Frame.Confirm
						local newColor = v
						local currentColor = v
						
						local function showColorPicker()
							color.BackgroundColor3 = currentColor
							red.Text = ored
							green.Text = ogreen
							blue.Text = oblue
							colorPicker.Visible = true
						end
						
						-- Color Picker
						
						local function updateColor()
							local nred,ngreen,nblue = tonumber(red.Text),tonumber(green.Text),tonumber(blue.Text)
							if not nred then
								nred = 0
							end
							if not ngreen then 
								ngreen = 0
							end
							if not nblue then 
								nblue = 0
							end
							if nred>255 then nred=255 end
							if ngreen>255 then ngreen=255 end
							if nblue>255 then nblue=255 end
							nred = math.floor(nred)
							ngreen = math.floor(ngreen)
							nblue = math.floor(nblue)
							red.Text = nred
							green.Text = ngreen
							blue.Text = nblue
							nred,ngreen,nblue = nred/255,ngreen/255,nblue/255
							newColor = Color3.new(nred,ngreen,nblue)
							color.BackgroundColor3 = newColor
						end
						
						red.Changed:connect(updateColor)
						green.Changed:connect(updateColor)
						blue.Changed:connect(updateColor)
						
						confirmColor.MouseButton1Click:connect(function()
							ored,ogreen,oblue = newColor.r*255,newColor.g*255,newColor.b*255
							currentColor = newColor
							colorPicker.Visible = false
							clone.TextButton.BackgroundColor3 = newColor
							sets[set] = newColor
							client.Remote.Send("SaveSetSetting",set,sets[set])
						end)
						
						cancelColor.MouseButton1Click:connect(function()
							newColor = currentColor
							colorPicker.Visible = false
						end)
						
						clone.TextButton.MouseButton1Down:connect(function()
							showColorPicker()
						end)
						
						clone.Parent = settingsTab.Settings
						num = num+1
					end
				elseif type(v)=="table" then
					local clone = tableBut:Clone()
					clone.Text = set..": "
					clone.TextButton.Text = "Edit"
					if descs[set] then
						clone.Desc.Value = descs[set]
					else
						clone.Desc.Value = set
					end
					clone.Position = UDim2.new(0,0,0,num*20)
					clone.Visible = true
					Expand(clone,desc)
					
					local function closeAll()
						for k,m in pairs(settingsTab:GetChildren()) do
							if m:IsA("Frame") and m.Name~="Settings" then
								m.Visible = false
							end
						end
					end
					
					if set=="Ranks" then
						local Ranks = settingsTab.Ranks:clone()
						Ranks.Parent = settingsTab
						local add = Ranks.Add
						local rem = Ranks.Removeb
						local close = Ranks.Close
						
						local newEntry = add.NewEntry
						local confirm = newEntry.Add
						local cancel = newEntry.Cancel
						local groupId = newEntry.Group
						local rank = newEntry.Rank
						local type = newEntry.Type
						
						local tab = Ranks.Table
						
						local entBut = Ranks.Entry
						
						local selectedEntry
						local selectedRank
						local selectedInd
						
						local function populate()
							tab:ClearAllChildren()
							local newm = 0
							for k,m in pairs(v) do
								local new = entBut:Clone()
								new.Text = "Group: "..m.Group.." | Rank: "..m.Rank.." | Type: "..m.Type
								new.Position = UDim2.new(0,0,0,newm*20)
								new.Visible = true
								new.ZIndex = 2
								new.Parent = tab
								new.MouseButton1Click:connect(function()
									if selectedEntry then
										selectedEntry.BackgroundTransparency = 1
									end
									new.BackgroundTransparency = 0
									selectedEntry = new
									selectedRank = m
									selectedInd = k
								end)
								newm=newm+1
							end
							tab.CanvasSize = UDim2.new(0,0,0,newm*20)
						end
						
						confirm.MouseButton1Click:connect(function()
							if groupId.Text~="" and rank.Text~="" and type.Text~="" then
								local tid = groupId.Text
								local tr = rank.Text
								local tt = type.Text
								
								groupId.Text=""
								rank.Text=""
								type.Text=""
								
								if tonumber(tid) then
									tid = tonumber(tid)
								end
								
								table.insert(sets[set],{Group=tid,Rank=tr,Type=tt})
								client.Remote.Send("SaveTableAdd",set,{Group=tid,Rank=tr,Type=tt})
								newEntry.Visible = false
								populate()
							end
						end)
						
						cancel.MouseButton1Click:connect(function()
							groupId.Text=""
							rank.Text=""
							type.Text=""
							newEntry.Visible = false
						end)
						
						rem.MouseButton1Click:connect(function()
							if selectedEntry and selectedRank and selectedInd then
								table.remove(sets[set],selectedInd)
								client.Remote.Send("SaveTableRemove",set,selectedRank)
								populate()
							end
						end)
						
						add.MouseButton1Click:connect(function()
							groupId.Text=""
							rank.Text=""
							type.Text=""
							closeAll()
							if newEntry.Visible then
								newEntry.Visible = false
							else
								newEntry.Visible = true
							end
						end)
						
						close.MouseButton1Click:connect(function()
							newEntry.Visible = false
							Ranks.Visible = false
						end)
						
						clone.TextButton.MouseButton1Click:connect(function()
							closeAll()
							if Ranks.Visible then
								Ranks.Visible = false
							else
								Ranks.Visible = true
							end
						end)
						
						populate()
					elseif set=="MusicList" then
						local Music = settingsTab.Music:clone()
						Music.Parent = settingsTab
						local tab = Music.Table
						local Add = Music.Add
						local Close = Music.Close
						local Entry = Music.Entry
						local Remove = Music.Removeb
						
						local newEnt = Add.NewEntry
						local newAdd = newEnt.Add
						local newCancel = newEnt.Cancel
						local newId = newEnt.ID
						local newName = newEnt.Nameb
						local newPitch = newEnt.Pitch
						local newVolume = newEnt.Volume
						
						local selectedEntry
						local selectedValue
						local selectedInd
						
						local function populate()
							tab:ClearAllChildren()
							local newm = 0
							for k,m in pairs(v) do
								local new = Entry:Clone()
								new.Text = "Name: "..m.Name.." | ID: "..m.Id.." | Pitch: "..(m.Pitch or "N/A").." | Volume: "..(m.Volume or "N/A")
								new.Position = UDim2.new(0,0,0,newm*20)
								new.Visible = true
								new.ZIndex = 2
								new.Parent = tab
								new.MouseButton1Click:connect(function()
									if selectedEntry then
										selectedEntry.BackgroundTransparency = 1
									end
									new.BackgroundTransparency = 0
									selectedEntry = new
									selectedValue = m
									selectedInd = k
								end)
								newm=newm+1
							end
							tab.CanvasSize = UDim2.new(0,0,0,newm*20)
						end
						
						newAdd.MouseButton1Click:connect(function()
							if newName.Text~="" and newPitch.Text~="" then
								local name = newName.Text
								local id = newId.Text
								local pitch = newPitch.Text
								local volume = newVolume.Text
								
								newName.Text = ""
								newId.Text = ""
								newPitch.Text = ""
								newVolume.Text = ""
								
								if pitch=="" then
									pitch = nil
								end
								if volume=="" then
									volume = nil
								end
								
								table.insert(sets[set],{Name=name,Id=id,Pitch=pitch,Volume=volume})
								client.Remote.Send("SaveTableAdd",set,{Name=name,Id=id,Pitch=pitch,Volume=volume})
								newEnt.Visible = false
								populate()
							end
						end)
						
						newCancel.MouseButton1Click:connect(function()
							newName.Text = ""
							newId.Text = ""
							newPitch.Text = ""
							newVolume.Text = ""
							newEnt.Visible = false
						end)
						
						Remove.MouseButton1Click:connect(function()
							if selectedEntry and selectedValue and selectedInd then
								table.remove(sets[set],selectedInd)
								client.Remote.Send("SaveTableRemove",set,selectedValue)
								populate()
							end
						end)
						
						Add.MouseButton1Click:connect(function()
							newName.Text = ""
							newId.Text = ""
							newPitch.Text = ""
							newVolume.Text = ""
							if newEnt.Visible then
								newEnt.Visible = false
							else
								newEnt.Visible = true
							end
						end)
						
						Close.MouseButton1Click:connect(function()
							newEnt.Visible = false
							Music.Visible = false
						end)
						
						clone.TextButton.MouseButton1Click:connect(function()
							closeAll()
							if Music.Visible then
								Music.Visible = false
							else
								Music.Visible = true
							end
						end)
						
						populate()
					elseif set=="CapeList" then
						local Capes = settingsTab.Capes:clone()
						Capes.Parent = settingsTab
						local tab = Capes.Table
						local Add = Capes.Add
						local Close = Capes.Close
						local Entry = Capes.Entry
						local Remove = Capes.Removeb
						
						local newEnt = Add.NewEntry
						local newAdd = newEnt.Add
						local newCancel = newEnt.Cancel
						local newId = newEnt.ID
						local newName = newEnt.Nameb
						local newMaterial = newEnt.Material
						local newReflectance = newEnt.Reflectance
						local newColor = newEnt.Color
						
						local selectedEntry
						local selectedValue
						local selectedInd
						
						local function populate()
							tab:ClearAllChildren()
							local newm = 0
							for k,m in pairs(v) do
								local new = Entry:Clone()
								new.Text = "Name: "..m.Name.." | Texture: "..(m.ID or "N/A").." | Color: "..(m.Color or "N/A").." | Material: "..(m.Material or "N/A").." | Reflectance: "..(m.Reflectance or "N/A")
								new.Position = UDim2.new(0,0,0,newm*20)
								new.Visible = true
								new.ZIndex = 2
								new.Parent = tab
								new.MouseButton1Click:connect(function()
									if selectedEntry then
										selectedEntry.BackgroundTransparency = 1
									end
									new.BackgroundTransparency = 0
									selectedEntry = new
									selectedValue = m
									selectedInd = k
								end)
								newm=newm+1
							end
							tab.CanvasSize = UDim2.new(0,0,0,newm*20)
						end
						
						newAdd.MouseButton1Click:connect(function()
							if newName.Text~="" then
								local name = newName.Text
								local id = newId.Text
								local material = newMaterial.Text
								local color = newColor.Text
								local reflectance = newReflectance.Text
								
								newName.Text = ""
								newId.Text = ""
								newMaterial.Text = ""
								newColor.Text = ""
								newReflectance.Text = ""
								
								if material=="" then
									material = nil
								end
								if color=="" then
									color = nil
								end
								if id=="" then
									id = nil
								end
								if reflectance=="" then
									reflectance = nil
								end
								
								table.insert(sets[set],{Name=name,ID=id,Color=color,Material=material,Reflectance=reflectance})
								client.Remote.Send("SaveTableAdd",set,{Name=name,ID=id,Color=color,Material=material,Reflectance=reflectance})
								newEnt.Visible = false
								populate()
							end
						end)
						
						newCancel.MouseButton1Click:connect(function()
							newName.Text = ""
							newId.Text = ""
							newMaterial.Text = ""
							newColor.Text = ""
							newReflectance.Text = ""
							newEnt.Visible = false
						end)
						
						Remove.MouseButton1Click:connect(function()
							if selectedEntry and selectedValue and selectedInd then
								table.remove(sets[set],selectedInd)
								client.Remote.Send("SaveTableRemove",set,selectedValue)
								populate()
							end
						end)
						
						Add.MouseButton1Click:connect(function()
							newName.Text = ""
							newId.Text = ""
							newMaterial.Text = ""
							newColor.Text = ""
							newReflectance.Text = ""
							if newEnt.Visible then
								newEnt.Visible = false
							else
								newEnt.Visible = true
							end
						end)
						
						Close.MouseButton1Click:connect(function()
							newEnt.Visible = false
							Capes.Visible = false
						end)
						
						clone.TextButton.MouseButton1Click:connect(function()
							closeAll()
							if Capes.Visible then
								Capes.Visible = false
							else
								Capes.Visible = true
							end
						end)
						
						populate()
					elseif set=="CommandPermissions" then
						local Perms = settingsTab.Permissions:clone()
						Perms.Parent = settingsTab
						local tab = Perms.Table
						local Add = Perms.Add
						local Close = Perms.Close
						local Entry = Perms.Entry
						local Remove = Perms.Removeb
						
						local newEnt = Add.NewEntry
						local newAdd = newEnt.Add
						local newCancel = newEnt.Cancel
						local newCommand = newEnt.Command
						local newLevel = newEnt.Level
						
						local selectedEntry
						local selectedValue
						local selectedInd
						
						local function populate()
							tab:ClearAllChildren()
							local newm = 0
							for k,m in pairs(v) do
								local new = Entry:Clone()
								new.Text = "Command: "..m.Command.." | Level: "..m.Level
								new.Position = UDim2.new(0,0,0,newm*20)
								new.Visible = true
								new.ZIndex = 2
								new.Parent = tab
								new.MouseButton1Click:connect(function()
									if selectedEntry then
										selectedEntry.BackgroundTransparency = 1
									end
									new.BackgroundTransparency = 0
									selectedEntry = new
									selectedValue = m
									selectedInd = k
								end)
								newm=newm+1
							end
							tab.CanvasSize = UDim2.new(0,0,0,newm*20)
						end
						
						newAdd.MouseButton1Click:connect(function()
							if newCommand.Text~="" and newLevel.Text~="" then
								local command = newCommand.Text
								local level = newLevel.Text
								
								newCommand.Text = ""
								newLevel.Text = ""
								
								table.insert(sets[set],{Command=command,Level=level})
								client.Remote.Send("SaveTableAdd",set,{Command=command,Level=level})
								newEnt.Visible = false
								populate()
							end
						end)
						
						newCancel.MouseButton1Click:connect(function()
							newCommand.Text = ""
							newLevel.Text = ""
							newEnt.Visible = false
						end)
						
						Remove.MouseButton1Click:connect(function()
							if selectedEntry and selectedValue and selectedInd then
								table.remove(sets[i],selectedInd)
								client.Remote.Send("SaveTableRemove",set,selectedValue)
								populate()
							end
						end)
						
						Add.MouseButton1Click:connect(function()
							newCommand.Text = ""
							newLevel.Text = ""
							if newEnt.Visible then
								newEnt.Visible = false
							else
								newEnt.Visible = true
							end
						end)
						
						Close.MouseButton1Click:connect(function()
							newEnt.Visible = false
							Perms.Visible = false
						end)
						
						clone.TextButton.MouseButton1Click:connect(function()
							closeAll()
							if Perms.Visible then
								Perms.Visible = false
							else
								Perms.Visible = true
							end
						end)
						
						populate()
					elseif set=="Leaderstats" then
						local Stats = settingsTab.Leaderstats:clone()
						Stats.Parent = settingsTab
						local tab = Stats.Table
						local Add = Stats.Add
						local Close = Stats.Close
						local Entry = Stats.Entry
						local Remove = Stats.Removeb
						
						local newEnt = Add.NewEntry
						local newAdd = newEnt.Add
						local newCancel = newEnt.Cancel
						local newStat = newEnt.Nameb
						local newType = newEnt.Type
						local newValue = newEnt.Value
						
						local selectedEntry
						local selectedValue
						local selectedInd
						
						local function populate()
							tab:ClearAllChildren()
							local newm = 0
							for k,m in pairs(v) do
								local new = Entry:Clone()
								new.Text = "Name: "..m.Stat.." | Type: "..m.Type.." | Value: "..m.Value
								new.Position = UDim2.new(0,0,0,newm*20)
								new.Visible = true
								new.ZIndex = 2
								new.Parent = tab
								new.MouseButton1Click:connect(function()
									if selectedEntry then
										selectedEntry.BackgroundTransparency = 1
									end
									new.BackgroundTransparency = 0
									selectedEntry = new
									selectedValue = m
									selectedInd = k
								end)
								newm=newm+1
							end
							tab.CanvasSize = UDim2.new(0,0,0,newm*20)
						end
						
						newAdd.MouseButton1Click:connect(function()
							if newStat.Text~="" and newType.Text~="" then
								local stat = newStat.Text
								local type = newType.Text
								local value = newValue.Text
								
								newStat.Text = ""
								newType.Text = ""
								newValue.Text = ""
								
								if type=="" then
									type="String"
								end
								
								table.insert(sets[set],{Stat=stat,Type=type,Value=value})
								client.Remote.Send("SaveTableAdd",set,{Stat=stat,Type=type,Value=value})
								newEnt.Visible = false
								populate()
							end
						end)
						
						newCancel.MouseButton1Click:connect(function()
							newStat.Text = ""
							newType.Text = ""
							newValue.Text = ""
							newEnt.Visible = false
						end)
						
						Remove.MouseButton1Click:connect(function()
							if selectedEntry and selectedValue and selectedInd then
								table.remove(sets[set],selectedInd)
								client.Remote.Send("SaveTableRemove",set,selectedValue)
								populate()
							end
						end)
						
						Add.MouseButton1Click:connect(function()
							newStat.Text = ""
							newType.Text = ""
							newValue.Text = ""
							if newEnt.Visible then
								newEnt.Visible = false
							else
								newEnt.Visible = true
							end
						end)
						
						Close.MouseButton1Click:connect(function()
							newEnt.Visible = false
							Stats.Visible = false
						end)
						
						clone.TextButton.MouseButton1Click:connect(function()
							closeAll()
							if Stats.Visible then
								Stats.Visible = false
							else
								Stats.Visible = true
							end
						end)
						
						populate()
					else
						local Normal = settingsTab.Normal:clone()
						Normal.Parent = settingsTab
						local tab = Normal.Table
						local Add = Normal.Add
						local Close = Normal.Close
						local Entry = Normal.Entry
						local Remove = Normal.Removeb
						
						local newEnt = Add.NewEntry
						local newAdd = newEnt.Add
						local newCancel = newEnt.Cancel
						local newValue = newEnt.Value
						
						local selectedEntry
						local selectedValue
						local selectedInd
						
						local function populate()
							tab:ClearAllChildren()
							local newm = 0
							for k,m in pairs(v) do
								local new = Entry:Clone()
								new.Text = tostring(m)
								new.Position = UDim2.new(0,0,0,newm*20)
								new.Visible = true
								new.ZIndex = 2
								new.Parent = tab
								
								new.MouseButton1Click:connect(function()
									if selectedEntry then
										selectedEntry.BackgroundTransparency = 1
									end
									new.BackgroundTransparency = 0
									selectedEntry = new
									selectedValue = m
									selectedInd = k
								end)
								newm=newm+1
							end
							tab.CanvasSize = UDim2.new(0,0,0,newm*20)
						end
						
						newAdd.MouseButton1Click:connect(function()
							if newValue.Text~="" then
								local value = newValue.Text
								newValue.Text = ""
								table.insert(sets[set],value)
								client.Remote.Send("SaveTableAdd",set,value)
								newEnt.Visible = false
								populate()
							end
						end)
						
						newCancel.MouseButton1Click:connect(function()
							newValue.Text = ""
							newEnt.Visible = false
						end)
						
						Remove.MouseButton1Click:connect(function()
							if selectedEntry and selectedValue and selectedInd then
								table.remove(sets[set],selectedInd)
								client.Remote.Send("SaveTableRemove",set,selectedValue)
								populate()
							end
						end)
						
						Add.MouseButton1Click:connect(function()
							if newEnt.Visible then
								newEnt.Visible = false
							else
								newEnt.Visible = true
							end
						end)
						
						Close.MouseButton1Click:connect(function()
							newEnt.Visible = false
							Normal.Visible = false
						end)
						
						clone.TextButton.MouseButton1Click:connect(function()
							closeAll()
							if Normal.Visible then
								Normal.Visible = false
							else
								Normal.Visible = true
							end
						end)
						
						populate()
					end
					clone.Parent = settingsTab.Settings
					num = num+1
				end
				settingsTab.Settings.CanvasSize = UDim2.new(0,0,0,num*20)
			end
		end
	else
		settings.Visible = false
	end
end
