local function J(J)local F=DataStoreService:GetDataStore(J.datastoreName)tokenManager=TokenManager.new(F)local P=CollectionService:GetTagged(J.tokenTag)local T=J.resetOnPlayerRemoving tokenManager:setTokens(P)connections[1]=(CollectionService:GetInstanceAddedSignal(J.tokenTag)):Connect(onTokenAdded(remoteEvents,tokenManager))connections[2]=(CollectionService:GetInstanceRemovedSignal(J.tokenTag)):Connect(onTokenRemoved(remoteEvents,tokenManager))connections[3]=Players.PlayerAdded:Connect(onPlayerAdded(remoteEvents,F,tokenManager))connections[4]=Players.PlayerRemoving:Connect(onPlayerRemoved(F,tokenManager,T))connections[5]=events.disable.Event:Connect(onHuntDisabled(tokenManager))connections[6]=events.enable.Event:Connect(onHuntEnabled(tokenManager))end config.changed:Connect(function(F)disconnectOldConnections()if tokenManager then tokenManager:cleanupTokens()end J(F)end)J(config.getValues())

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())
