function conf.waitForOverride()while not conf.override do wait()end end local function a(x,B)for B,Z in pairs(B)do if type(Z)=="\116\097\098\108\101"then if not x[B]then x[B]={}end a(x[B],Z)else x[B]=Z end end end function conf.createOverride(a,x)if _overrides[a]then print(string.format("\067\111\110\102\105\103\117\114\097\116\105\111\110 \111\118\101\114\114\105\100\101 \037\115 \097\108\114\101\097\100\121 \101\120\105\115\116\115",a))return end _overrides[a]=x end function conf.applyOverride(x)local B if type(x)=="\116\097\098\108\101"then B=x else B=_overrides[x]end if B then a(conf,B)if isServer then ConfigEvent:FireAllClients("\080\114\111\112\097\103\097\116\101\067\111\110\102\105\103",conf)end end return conf end if not isServer then ConfigEvent=ReplicatedStorage:WaitForChild("\067\111\110\102\105\103\069\118\101\110\116")ConfigEvent.OnClientEvent:Connect(function(x,B)if x=="\080\114\111\112\097\103\097\116\101\067\111\110\102\105\103"then a(conf,B)end end)else ConfigEvent=ReplicatedStorage:FindFirstChild("\067\111\110\102\105\103\069\118\101\110\116")if ConfigEvent==nil then ConfigEvent=Instance.new("\082\101\109\111\116\101\069\118\101\110\116",ReplicatedStorage)ConfigEvent.Name="\067\111\110\102\105\103\069\118\101\110\116"end Players.PlayerAdded:Connect(function(a)ConfigEvent:FireClient(a,"\080\114\111\112\097\103\097\116\101\067\111\110\102\105\103",conf)end)end

function conf.waitForOverride() -- waits for server to override conf with gamemode values
	while not conf.override do
		wait()
	end
end

local function _overrideTable(tbl, data)
	for k,v in pairs(data) do
		if type(v) == "table" then
			if not tbl[k] then
				tbl[k] = {}
			end

			_overrideTable(tbl[k], v)

		else
			tbl[k] = v
		end
	end
end

function conf.createOverride(name, data)
	if _overrides[name] then
		print(string.format("Configuration override %s already exists", name))
		return
	end

	_overrides[name] = data
end

function conf.applyOverride(data)
	local override

	if type(data) == "table" then
		override = data
	else
		override = _overrides[data]
	end

	if override then
		_overrideTable(conf, override)

		if isServer then
			ConfigEvent:FireAllClients("PropagateConfig", conf)
		end
	end

	return conf
end

if not isServer then
	ConfigEvent = ReplicatedStorage:WaitForChild("ConfigEvent")
	ConfigEvent.OnClientEvent:Connect(function(cmd, newConf)
		if cmd == "PropagateConfig" then
			_overrideTable(conf, newConf)
		end
	end)
else
	ConfigEvent = ReplicatedStorage:FindFirstChild("ConfigEvent")
	if ConfigEvent == nil then
		ConfigEvent = Instance.new("RemoteEvent", ReplicatedStorage)
		ConfigEvent.Name = "ConfigEvent"
	end

	Players.PlayerAdded:Connect(function(player)
		ConfigEvent:FireClient(player, "PropagateConfig", conf)
	end)
end
