function conf.waitForOverride()while not conf.override do wait()end end local function X(G,F)for F,c in pairs(F)do if type(c)=="\116\097\098\108\101"then if not G[F]then G[F]={}end X(G[F],c)else G[F]=c end end end function conf.createOverride(X,G)if _overrides[X]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",X))return end _overrides[X]=G end function conf.applyOverride(G)local F if type(G)=="\116\097\098\108\101"then F=G else F=_overrides[G]end if F then X(conf,F)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(G,F)if G=="\080\114\111\112\097\103\097\116\101\067\111\110\102\105\103"then X(conf,F)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(X)ConfigEvent:FireClient(X,"\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
