local function f(f)local G=DataStoreService:GetDataStore(f.datastoreName)tokenManager=TokenManager.new(G)local m=CollectionService:GetTagged(f.tokenTag)local q=f.resetOnPlayerRemoving tokenManager:setTokens(m)connections[1]=(CollectionService:GetInstanceAddedSignal(f.tokenTag)):Connect(onTokenAdded(remoteEvents,tokenManager))connections[2]=(CollectionService:GetInstanceRemovedSignal(f.tokenTag)):Connect(onTokenRemoved(remoteEvents,tokenManager))connections[3]=Players.PlayerAdded:Connect(onPlayerAdded(remoteEvents,G,tokenManager))connections[4]=Players.PlayerRemoving:Connect(onPlayerRemoved(G,tokenManager,q))connections[5]=events.disable.Event:Connect(onHuntDisabled(tokenManager))connections[6]=events.enable.Event:Connect(onHuntEnabled(tokenManager))end config.changed:Connect(function(G)disconnectOldConnections()if tokenManager then tokenManager:cleanupTokens()end f(G)end)f(config.getValues())
--[[
	Connect to the datastore, set up connections and create resources used by
	the server

	Parameters:
	configValues: A table containing configuration values
]]
local function setup(configValues)
	local tokenDataStore = DataStoreService:GetDataStore(configValues.datastoreName)
	tokenManager = TokenManager.new(tokenDataStore)
	local tokens = CollectionService:GetTagged(configValues.tokenTag)
	local resetOnPlayerRemoving = configValues.resetOnPlayerRemoving

	tokenManager:setTokens(tokens)

	connections[1] = CollectionService:GetInstanceAddedSignal(configValues.tokenTag)
		:Connect(onTokenAdded(remoteEvents, tokenManager))
	connections[2] = CollectionService:GetInstanceRemovedSignal(configValues.tokenTag)
		:Connect(onTokenRemoved(remoteEvents, tokenManager))
	connections[3] = Players.PlayerAdded:Connect(onPlayerAdded(remoteEvents, tokenDataStore, tokenManager))
	connections[4] =
		Players.PlayerRemoving:Connect(onPlayerRemoved(tokenDataStore, tokenManager, resetOnPlayerRemoving))
	connections[5] = events.disable.Event:Connect(onHuntDisabled(tokenManager))
	connections[6] = events.enable.Event:Connect(onHuntEnabled(tokenManager))
end

config.changed:Connect(function(configValues)
	-- Clean up old data if it exists
	disconnectOldConnections()
	if tokenManager then
		tokenManager:cleanupTokens()
	end

	setup(configValues)
end)

setup(config.getValues())
