local module = {}

local rules = {}
module.rules = rules
local listeners = {}

function module.listenRule(name,callback)
	if rules[name] then task.spawn(callback,rules[name]) end
	if not listeners[name] then listeners[name] = {} end
	table.insert(listeners[name],callback)
end

function module.setRule(name,value)
	_G.Remotes.Rule:FireAllClients(name,value)
	if not rules[name] then rules[name] = {} end
	if not listeners[name] then listeners[name] = {} end
	rules[name] = value
	for _,callback in pairs(listeners[name]) do
		task.spawn(callback,value)
	end
end

if _G.IsClient then
	_G.Remotes.Rule.OnClientEvent:Connect(module.setRule)
end

return module