local function C()for C,Q in pairs(pages.custom:GetChildren())do local A=string.sub(Q.Name,5)if Q:FindFirstChild("\083\101\116\116\105\110\103\086\097\108\117\101")then Q.SettingName.TextLabel.Text=A.."\058"local C=main.pdata[A]Q.SettingValue.TextBox.Text=tostring(C)local m local L if string.sub(A,1,5)=="\069\114\114\111\114"then m="\069\114\114\111\114"L=6 elseif string.sub(A,1,6)=="\078\111\116\105\099\101"then m="\078\111\116\105\099\101"L=7 end if m then local Q=main.audio[m]local Y=string.sub(A,L)if Y=="\083\111\117\110\100\073\100"then C="\114\098\120\097\115\115\101\116\105\100\058\047\047"..C end Q[Y]=C end end end updateThemeSelection()end for Q,A in pairs(pages.custom:GetChildren())do local m=string.sub(A.Name,5)if A:FindFirstChild("\083\101\116\116\105\110\103\086\097\108\117\101")then local Q=true local L=A.SettingValue.TextBox local Y=A.SettingValue.TextLabel A.SettingValue.TextBox.FocusLost:connect(function(q)if Q then local q=A.SettingValue.TextBox.Text Q=false L.Visible=false Y.Visible=true Y.Text="\076\111\097\100\105\110\103\046\046\046"local N=main.signals.ChangeSetting:InvokeServer({m;q})if N=="\083\117\099\099\101\115\115"then C()local Q="\078\111\116\105\099\101"local A=string.sub(m,1,5)if A=="\069\114\114\111\114"or A=="\065\108\101\114\116"then Q=A end if m=="\080\114\101\102\105\120"then(main:GetModule("\080\097\103\101\067\111\109\109\097\110\100\115")):CreateCommands()end local L="\083\117\099\099\101\115\115\102\117\108\108\121 \099\104\097\110\103\101\100 \'"..(m..("\' \116\111 \'"..(q.."\'")))if Q=="\065\108\101\114\116"then(main:GetModule("\099\102")):CreateNewCommandMenu("\115\101\116\116\105\110\103\115",{"\083\101\116\116\105\110\103\115 \065\108\101\114\116";L},8,true)else(main:GetModule("\078\111\116\105\099\101\115")):Notice(Q,"\083\101\116\116\105\110\103\115",L)end else Y.Text=N wait(1)end L.Visible=true Y.Visible=false A.SettingValue.TextBox.Text=tostring(main.pdata[m])Q=true end end)end end C()

local function updateSettings()
	for a,b in pairs(pages.custom:GetChildren()) do
		local settingName = string.sub(b.Name, 5)
		if b:FindFirstChild("SettingValue") then
			b.SettingName.TextLabel.Text = settingName..":"
			local settingValue = main.pdata[settingName]
			b.SettingValue.TextBox.Text = tostring(settingValue)
			local soundName
			local propertyStart
			if string.sub(settingName, 1, 5) == "Error" then
				soundName = "Error"
				propertyStart = 6
			elseif string.sub(settingName, 1, 6) == "Notice" then
				soundName = "Notice"
				propertyStart = 7
			end
			if soundName then
				local sound = main.audio[soundName]
				local propertyName = string.sub(settingName, propertyStart)
				if propertyName == "SoundId" then
					settingValue = "rbxassetid://"..settingValue
				end
				sound[propertyName] = settingValue
			end
		end
	end
	updateThemeSelection()
end
for a,b in pairs(pages.custom:GetChildren()) do
	local settingName = string.sub(b.Name, 5)
	if b:FindFirstChild("SettingValue") then
		local settingDe = true
		local textBox = b.SettingValue.TextBox
		local textLabel = b.SettingValue.TextLabel
		b.SettingValue.TextBox.FocusLost:connect(function(property)
			if settingDe then
				local newValue = b.SettingValue.TextBox.Text
				settingDe = false
				textBox.Visible = false
				textLabel.Visible = true
				textLabel.Text = "Loading..."
				local returnMsg = main.signals.ChangeSetting:InvokeServer{settingName, newValue}
				if returnMsg == "Success" then
					updateSettings()
					local noticeType = "Notice"
					local settingType = string.sub(settingName, 1, 5)
					if settingType == "Error" or settingType == "Alert" then
						noticeType = settingType
					end
					if settingName == "Prefix" then
						main:GetModule("PageCommands"):CreateCommands()
					end
					local noticeMessage = "Successfully changed '"..settingName.."' to '"..newValue.."'"
					if noticeType == "Alert" then
						main:GetModule("cf"):CreateNewCommandMenu("settings", {"Settings Alert", noticeMessage}, 8, true)
					else
						main:GetModule("Notices"):Notice(noticeType, "Settings", noticeMessage)
					end
				else
					textLabel.Text = returnMsg
					wait(1)
				end
				textBox.Visible = true
				textLabel.Visible = false
				b.SettingValue.TextBox.Text = tostring(main.pdata[settingName])
				settingDe = true
			end
		end)
	end
end
updateSettings()
